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(); }
/// <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 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(); } }
private void BusyableDialogWindow_Closed(object sender, EventArgs e) { // TokenSources need to be disposed, so here it is. if (TokenSource != null) { TokenSource.Dispose(); } }
public void DisposeToken() { if (TokenSource is object) { TokenSource.Dispose(); TokenSource = null; } }
/// <summary> /// Disposes this object /// </summary> public void Dispose() { if (isDisposed) { return; } TokenSource.Dispose(); isDisposed = true; }
public void Dispose() { if (TokenSource is null) { return; } TokenSource.Cancel(); TokenSource.Dispose(); TokenSource = null; }
public void Disconnect() { if (!Connected) { Logger.Log(Logger.Level.Info, "A disconnection request was made while already disconnected. Skipping."); return; } Logger.Log(Logger.Level.Info, "Attempting to disconnect from the remote socket."); Connected = false; if (TokenSource != null) { Logger.Log(Logger.Level.Debug, "Cancelling and disposing of TokenSource"); if (!TokenSource.IsCancellationRequested) { TokenSource.Cancel(); } TokenSource.Dispose(); TokenSource = null; } else { Logger.Log(Logger.Level.Debug, "TokenSource already cancelled. Skipping."); } if (NetworkStream != null) { // Network stream must be disconnected and disposed separately Logger.Log(Logger.Level.Debug, "Closing and disposing of network stream"); NetworkStream.Close(); NetworkStream.Dispose(); NetworkStream = null; } else { Logger.Log(Logger.Level.Debug, "Network stream already closed. Skipping."); } if (Client != null) { Logger.Log(Logger.Level.Debug, "Closing and disposing of socket instance"); Client.Close(); Client.Dispose(); Client = null; } else { Logger.Log(Logger.Level.Debug, "Socket instance already closed. Skipping"); } Logger.Log(Logger.Level.Info, "Disconnected from the remote socket"); }
/// <summary> /// Safely close client and break all connections to server. /// </summary> public override void Dispose() { Close(); ConnectedMre.Dispose(); SentMre.Dispose(); KeepAliveTimer.Enabled = false; KeepAliveTimer.Dispose(); TokenSource.Dispose(); GC.SuppressFinalize(this); }
public void Dispose() { _logger.LogInformation("Server: Stop listening..."); if (TokenSource is null) { return; } TokenSource.Cancel(); TokenSource.Dispose(); TokenSource = null; }
public void Dispose() { if (!IsDisposing) { IsDisposing = true; Status = IndexStatus.Disposing; TokenSource.Cancel(); TokenSource.Dispose(); FilesWatcher?.Dispose(); IndexBuilder?.Dispose(); Status = IndexStatus.Disposed; } }
//public static string DateUniqeServ = ""; protected override void OnDisappearing() { try { TokenSource.Cancel(); TokenSource.Dispose(); } catch { } MessagingCenter.Send <Object>(this, "AutoUpdate"); base.OnDisappearing(); }
private void kopatorMainForm_FormClosing(object oSender, FormClosingEventArgs oArgs) { if (IsProcessing) { oArgs.Cancel = true; return; } Settings.Default.Cut = cbMove.Checked; Settings.Default.TabPage = oTabControl.SelectedIndex; Settings.Default.Save(); TokenSource?.Dispose(); }
public void Dispose() { if (TokenSource != null) { if (!TokenSource.IsCancellationRequested) { TokenSource.Cancel(); } TokenSource.Dispose(); TokenSource = null; } if (_SslStream != null) { try { _SslStream.Close(); } catch (Exception) { } } if (_NetworkStream != null) { try { _NetworkStream.Close(); } catch (Exception) { } } if (_TcpClient != null) { try { _TcpClient.Close(); _TcpClient.Dispose(); _TcpClient = null; } catch (Exception) { } } }
public void DisposeReset() { try { if (Task != null) { Task.Dispose(); Task = null; } if (TokenSource != null) { TokenSource.Dispose(); TokenSource = new CancellationTokenSource(); } } catch { } }
/// <summary> /// Tear down the object and dispose of resources. /// </summary> public void Dispose() { if (_SslStream != null) { _SslStream.Close(); _SslStream.Dispose(); _SslStream = null; } if (_NetworkStream != null) { _NetworkStream.Close(); _NetworkStream.Dispose(); _NetworkStream = null; } if (TokenSource != null) { if (!TokenSource.IsCancellationRequested) { TokenSource.Cancel(); } TokenSource.Dispose(); TokenSource = null; } if (WriteLock != null) { WriteLock.Dispose(); WriteLock = null; } if (ReadLock != null) { ReadLock.Dispose(); ReadLock = null; } if (_TcpClient != null) { _TcpClient.Close(); _TcpClient.Dispose(); _TcpClient = null; } }
public override void Dispose() { if (IsDisposed) { return; } try { Stop(); Listener.Close(); TokenSource?.Dispose(); } finally { IsDisposed = true; } }
public void Dispose() { if (!IsDisposed) { IsDisposed = true; try { TokenSource.Cancel(); } catch { } TokenSource.Dispose(); SemaphoreCount.Dispose(); lock (Data) { Data.Clear(); } } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). _destinationStream = null; if (TokenSource != null) { TokenSource.Cancel(); TokenSource.Dispose(); TokenSource = null; } } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }
public void Reset() { IsActive = false; if (TokenSource != null) { if (!TokenSource.IsCancellationRequested) { TokenSource.Cancel(); TokenSource.Dispose(); } } if (NetworkStream != null) { NetworkStream.Close(); } if (TcpClient != null) { TcpClient.Close(); TcpClient.Dispose(); } }
public async void btCopy_Click(object oSender, EventArgs oArgs) { try { TokenSource ??= new CancellationTokenSource(); if (IsProcessing) { TokenSource?.Cancel(); return; } await _currentControl.Run().ConfigureAwait(true); } catch (Exception oException) { MessageBox.Show(oException.ToString()); } finally { ProgressBar.ResetText(); TokenSource?.Dispose(); } }
public void Dispose() { Cancel(DelayAfterError); TokenSource?.Dispose(); }
public override void Start() { if (IsDisposed) { throw new ObjectDisposedException(GetType().FullName); } if (IsListening || IsStarting || IsStopping) { return; } IsStarting = true; var exceptionWasThrown = false; try { // 1. Reset CancellationTokenSource TokenSource?.Dispose(); TokenSource = new CancellationTokenSource(); // 2. Execute BeforeStarting event handlers BeforeStarting?.Invoke(this); // 3. Optionally autoscan for routes if (Router.RoutingTable.Count == 0 && Options.EnableAutoScan) { Router.Register(RouteScanner.Scan()); } // 4. Configure and start the listener Listener.Start(); // 5. Start the request handler thread RequestHandler.Start(); // 6. Execute AfterStarting event handlers AfterStarting?.Invoke(this); } catch (HttpListenerException hl) when(hl.ErrorCode == 32) { /* * When the port you are attempting to bind to is already in use * by another application, the error can sometimes be unintuitive. */ exceptionWasThrown = true; var message = $"One or more ports are already in use by another application."; var exception = new ArgumentException(message, hl); Logger.LogCritical(exception, message); throw exception; } catch (Exception e) { exceptionWasThrown = true; Logger.LogCritical(e, "An unexpected error occured when attempting to start the server"); throw; } finally { if (exceptionWasThrown) { Listener.Stop(); TokenSource.Cancel(); } IsStarting = false; } }
public void Dispose() { //Dispose isDisposed = true; TokenSource.Dispose(); }
public void Dispose() { TokenSource.Dispose(); }
public void Dispose() { Stop(); TokenSource?.Dispose(); }
public void Dispose() { TokenSource?.Cancel(); TokenSource?.Dispose(); Responses?.CompleteAdding(); }
/// <summary> /// アニメーションを開始する /// </summary> /// <param name="visible">ウィンドウの表示・非表示</param> private bool StartAnimation(bool visible) { if (TokenSource != null) { if (IsAnimation) { TokenSource.Cancel(); } TokenSource.Dispose(); TokenSource = null; } TokenSource = new CancellationTokenSource(); CancelToken = TokenSource.Token; if ((!visible && FormVisible) || (visible && !FormVisible)) { GHFormDraw(); FormVisible = visible; // 非表示遅延時間の更新 HideTimer.Interval = animateInfo._DelayTime; IsAnimation = true; StopwatchTotal = 0; // スライドアニメーション if (animateInfo._Slide) { RemainingDistanceOfSlide = 0; if (GHManager.IsVertical) { Left = !visible ? GHFormShowPosition : GHFormHidePosition; } else { Top = !visible ? GHFormShowPosition : GHFormHidePosition; } } else { // スライドなしフェード if (GHManager.IsVertical) { Left = GHFormHidePosition = GHFormShowPosition; } else { Top = GHFormHidePosition = GHFormShowPosition; } } // フェードアニメーション if (animateInfo._Fade) { animateInfo._Alpha = (byte)(!visible ? 255 : 0); } else { // フェードなしスライド if (animateInfo._Slide) { animateInfo._Alpha = 255; } else { animateInfo._Alpha = (byte)(!visible ? 0 : 255); } } // アニメーション開始 AnimationStopwatch.Restart(); GHFormAnimation(CancelToken); // ランチャーを最前面 GHManager.ItemList.BringToFront(); GHManager.MysetList.BringToFront(); GHManager.Launcher.BringToFront(); return(true); } return(false); }