/// <summary> /// Closes the client. /// </summary> public void Close() { try { if (Disposed) { return; } ConnectedMre.Reset(); TokenSource.Cancel(); IsRunning = false; if (Listener == null) { return; } Listener.Shutdown(SocketShutdown.Both); Listener.Close(); Listener = null; RaiseDisconnected(); } catch (SocketException se) { throw new Exception(se.ToString()); } }
public LearningViewModel() { NetworkLearning = new RelayCommand(async() => { if (LearningData != null) { if (!IsRunning && !LoadingData) { IsRunning = true; TokenSource = new CancellationTokenSource(); Token = TokenSource.Token; await Task.Run(() => StartLearning(Token)); } } }); StopLearning = new RelayCommand(() => { if (IsRunning == true) { TokenSource.Cancel(); IsRunning = false; } }); LoadNetworkSource = new RelayCommand(async() => await Task.Run(() => LoadNetwork())); CreateNewNetwork = new RelayCommand(() => NewNetwork()); LoadLearningSource = new RelayCommand(async() => { await Task.Run(() => LoadMaterial()); }); }
/// <inheritdoc /> /// <summary> /// Properly dispose the class. /// </summary> public override void Dispose() { try { if (!Disposed) { TokenSource.Cancel(); TokenSource.Dispose(); IsRunning = false; Listener.Dispose(); CanAcceptConnections.Dispose(); _keepAliveTimer.Enabled = false; _keepAliveTimer.Dispose(); foreach (var id in ConnectedClients.Keys.ToList()) { Close(id); } ConnectedClients = new Dictionary <int, IClientMetadata>(); TokenSource.Dispose(); Disposed = true; GC.SuppressFinalize(this); } else { throw new ObjectDisposedException(nameof(SimpleSocketListener), "This object is already disposed."); } } catch (Exception ex) { throw new Exception(ex.Message, ex); } }
public void StopTask() { TokenSource.Cancel(); Debug.WriteLine("Maw, stop task asked"); // throw new System.NotImplementedException(); }
async Task close() { if (TokenSource != null) { TokenSource.Cancel(); } await Semaphore.WaitAsync(); try { ViewModel.endVideoPreview(); previewImage.Source = ViewModel.MediaPreviewImage; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this); if (adornerLayer != null) { adornerLayer.Remove(TimeAdorner); } } finally { Semaphore.Release(); } }
private async Task VoiceWS_SocketClosed(SocketCloseEventArgs e) { Discord.DebugLogger.LogMessage(LogLevel.Debug, "VoiceNext", $"Voice socket closed ({e.CloseCode.ToString(CultureInfo.InvariantCulture)}, '{e.CloseMessage}')", DateTime.Now); // generally this should not be disposed on all disconnects, only on requested ones // or something // otherwise problems happen //this.Dispose(); if (e.CloseCode == 4006 || e.CloseCode == 4009) { Resume = false; } if (!IsDisposed) { TokenSource.Cancel(); TokenSource = new CancellationTokenSource(); VoiceWs = Discord.Configuration.WebSocketClientFactory(Discord.Configuration.Proxy); VoiceWs.Disconnected += VoiceWS_SocketClosed; VoiceWs.MessageRecieved += VoiceWS_SocketMessage; VoiceWs.Connected += VoiceWS_SocketOpened; await ConnectAsync().ConfigureAwait(false); } }
public void RaisesNegativeEventsOnCancel() { bool cancelEventCalled = false; bool hasFailed = false; Exception exception = null; Shtirlitz.ReportCanceled += (sender, args) => { cancelEventCalled = true; hasFailed = args.HasFailed; exception = args.Exception; }; TokenSource.Cancel(); Assert.Throws <AggregateException>(() => RunSynchronously(true)); // wait a bit for a continuation to execute Thread.Sleep(1000); Assert.True(cancelEventCalled); Assert.False(hasFailed); AggregateException aggregateException = exception as AggregateException; Assert.NotNull(aggregateException); // ReSharper disable PossibleNullReferenceException Assert.IsType <OperationCanceledException>(aggregateException.InnerException); // ReSharper restore PossibleNullReferenceException }
public void Stop() { if (IsConsuming()) { TokenSource.Cancel(); } }
public void ExceptQueryCancellation() { var query = @"select City, Sum(Population) from #A.Entities() group by City except (City) select City, Sum(Population) from #B.Entities() group by City except (City) select City, Sum(Population) from #C.Entities() group by City"; var sources = new Dictionary <string, IEnumerable <BasicEntity> > { { "#A", new[] { new BasicEntity("001", "", 100), new BasicEntity("001", "", 100), new BasicEntity("002", "", 500) } }, { "#B", new[] { new BasicEntity("003", "", 13), new BasicEntity("003", "", 13), new BasicEntity("003", "", 13) } }, { "#C", new[] { new BasicEntity("002", "", 14), new BasicEntity("002", "", 14) } } }; var vm = CreateAndRunVirtualMachine(query, sources); TokenSource.Cancel(); vm.Run(TokenSource.Token); }
public void Stop() { TokenSource?.Cancel(); Socket?.Stop(); TokenSource = null; Socket = null; }
private async Task Filter() { TokenSource.Cancel(); var query = from feed in await RSSDataService.GetFeedsDataAsync(0) select feed; if (FilterSelectedSource != null) { query = query.Where(x => x.PostSource.Id == FilterSelectedSource.Id); } if (!string.IsNullOrWhiteSpace(FilterTitle)) { query = query.Where(x => x.PostTitle.ToLower().Contains(FilterTitle.ToLower())); } if (!string.IsNullOrWhiteSpace(FilterCreator)) { query = query.Where(x => x.Authors.Any(x => x.Email.ToLower() == FilterCreator.ToLower())); } if (FilterIsUnreadOnly) { query = query.Where(x => x.IsRead == false); } Feeds.Clear(); foreach (var item in query) { Feeds.Add(item); } }
public void Dispose() { if (TokenSource != null) { if (!TokenSource.IsCancellationRequested) { TokenSource.Cancel(); TokenSource.Dispose(); } } if (_sslStream != null) { _sslStream.Close(); } if (_networkStream != null) { _networkStream.Close(); } if (_tcpClient != null) { _tcpClient.Close(); _tcpClient.Dispose(); } SendLock.Dispose(); ReceiveLock.Dispose(); }
public virtual void Disconnect() { TokenSource.Cancel(); this.IsActive = false; this.ConnectionState = ConnState.DISCONNECTED; this.isConnected = false; }
private void UpgradeButton_Click(object sender, RoutedEventArgs e) { if (GameViewModel.Instance.GoldCounter < RessourceProducer.Price) { int rest = RessourceProducer.Price - GameViewModel.Instance.GoldCounter; System.Windows.MessageBox.Show("Il vous manque " + rest + " Golds !"); } else { TokenSource.Cancel(); RessourceProducer.Level = RessourceProducer.Level + 1; GameViewModel.Instance.GoldCounter -= RessourceProducer.Price; RessourceProducer.QuantityProduct += 10; RessourceProducer.Price *= 2; RefreshView(); TokenSource = new CancellationTokenSource(); Token = TokenSource.Token; Task usineUnTask = new Task(() => { GameViewModel.Instance.UsineProduction(RessourceProducer.ProductSpeed, RessourceProducer.QuantityProduct, TokenSource); }, Token); usineUnTask.Start(); if (RessourceProducer.Level == 5) { view.UpgradeButton.Content = "Maxed"; view.UpgradeButton.IsEnabled = false; } } }
public void Dispose() { if (TokenSource != null) { if (!TokenSource.IsCancellationRequested) { TokenSource.Cancel(); TokenSource.Dispose(); } } if (_SslStream != null) { _SslStream.Close(); } if (_NetworkStream != null) { _NetworkStream.Close(); } if (_TcpClient != null) { _TcpClient.Close(); _TcpClient.Dispose(); } }
/// <summary> /// Disconnects and disposes this voice connection. /// </summary> public void Dispose() { if (IsDisposed) { return; } IsDisposed = true; IsInitialized = false; TokenSource.Cancel(); #if !NETSTANDARD1_1 if (Configuration.EnableIncoming) { ReceiverTokenSource.Cancel(); } #endif try { VoiceWs.DisconnectAsync(null).ConfigureAwait(false).GetAwaiter().GetResult(); UdpClient.Close(); } catch (Exception) { } Opus?.Dispose(); Opus = null; Sodium = null; Rtp = null; if (VoiceDisconnected != null) { VoiceDisconnected(Guild); } }
public void Cancell() { if (TokenSource != null && !TokenSource.IsCancellationRequested) { TokenSource.Cancel(); } }
private async Task searchAsync(IClientServiceRequest request, String searchInfo, bool isNextPage) { if (SearchTask != null && !SearchTask.IsCompleted) { try { TokenSource.Cancel(); await SearchTask; } catch (OperationCanceledException) { } finally { TokenSource = new CancellationTokenSource(); } } try { SearchTask = search(request, searchInfo, isNextPage, TokenSource.Token); await SearchTask; } catch (OperationCanceledException) { } catch (Exception e) { MessageBox.Show(e.Message, "Youtube Search Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public override void Stop() { if (IsDisposed) { throw new ObjectDisposedException(GetType().FullName); } if (IsStopping || IsStarting) { return; } IsStopping = true; try { // 1. Execute BeforeStopping event handlers BeforeStopping?.Invoke(this); // 2. Stop the listener Listener?.Stop(); // 3. Complete or cancel running routes TokenSource?.Cancel(); // 4. Execute AfterStopping event handlers AfterStopping?.Invoke(this); } catch (Exception) { throw; } finally { IsStopping = false; } }
public void Stop() { if (Status == STARTED) { TokenSource.Cancel(); Status = STOPPED; } }
/// <summary> /// Signal to stop monitoring /// </summary> public void StopMonitoring(Server server) { if (Token.CanBeCanceled) { TokenSource.Cancel(); Log.Verbose($"Server {server.ID:00} Performance Monitor cancelled quietly."); } }
public void Cancel() { if (TokenSource != null) { TokenSource.Cancel(); TokenSource = null; } }
public void StopTask() { TokenSource.Cancel(); #if DEBUG Debug.WriteLine($"[AM_ProgressC] Cancel token requested"); #endif }
/// <summary> /// Stop scanning. /// </summary> public void Stop() { if (!IsStopped) { IsStopped = true; TokenSource.Cancel(); } }
public async Task CanBeCancelledImmediately() { TokenSource.Cancel(); await Target.RefreshContinuouslyAsync(TokenSource.Token); Factory.Verify(x => x.RefreshAsync(It.IsAny <CancellationToken>()), Times.Never); }
public void Cancel() { _isCancelled = true; TokenSource.Cancel(); Task.WaitAll(this); _isRunning = false; }
public override async Task DisconnectAsync() { TokenSource.Cancel(); await WebSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Shutdown procedure started", CancellationToken.None); InvokeOnClose(new OnCloseEventHandlerArgs(this)); ClientLoopTask.Wait(); }
public void Cancel(TimeSpan timeout) { if (TokenSource.IsCancellationRequested) { return; } TokenSource.Cancel(); RunnerThread.Join(timeout); }
public virtual void Stop() { Running = false; if (!TokenSource.IsCancellationRequested) { TokenSource.Cancel(); } }
/// <summary> /// WebSocketから切断する /// </summary> /// <returns></returns> public Task DisconnectAsync() { if (!IsConnected) { return(Task.CompletedTask); } TokenSource.Cancel(); return(WebSocketConnectionTask); }