private void CancelAll() { Cts.Cancel(); Cts.Dispose(); Cts = new CancellationTokenSource(); ActiveDownloads.Clear(); }
public static void Exit(ExitResult result) { if (Cts != null && !Cts.Token.CanBeCanceled) { Cts.Cancel(); Cts.Dispose(); } Environment.Exit((int)result); }
static void Exit(ExitResult result) { if (Cts != null) { Cts.Dispose(); } Environment.Exit((int)result); }
public void Clear() { Cts?.Dispose(); Cts = new CancellationTokenSource(); Package.FileName = null; Package.TotalFileSize = 0; Package.BytesReceived = 0; Package.Chunks = null; }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); Cts.Dispose(); } base.Dispose(disposing); }
public override void Begin(Func <CancellationToken, Task> action = null, Action <Exception> onError = null) { ThrowIfDisposed(); lock (Sync) { if (IsActive) { return; } IsActive = true; Cts?.Dispose(); Cts = new CancellationTokenSource(); } if (action != null) { Action = action; } if (onError != null) { ErrorAction = onError; } Task = Task.Run(async() => { while (!Cts.IsCancellationRequested) { try { await Action(Cts.Token).ConfigureAwait(false); } catch (OperationCanceledException) { /* ignored */ } catch (Exception e) { if (!Cts.IsCancellationRequested) { try { ErrorAction?.Invoke(e); } catch { /* ignored */ } OnError(e); } } try { if (!Cts.IsCancellationRequested) { await DelayAsync(Cts.Token).ConfigureAwait(false); } } catch { /* ignored */ } } }); }
private void Dispose(bool disposing) { if (!disposing) { return; } Cts?.Dispose( ); fiatMonitor?.Dispose( ); }
public void Close() { _cts?.Cancel(); _cts?.Dispose(); _channel?.Writer.Complete(); try { _udp.Close(); } catch { } }
public void Dispose() { if (m_Disposed) { return; } //Dispose the cancellation token source Cts.Dispose(); m_Disposed = true; }
protected virtual void Dispose(bool disposing) { if (!disposing || disposed) { return; } if (Cts != null) { Cts.Dispose(); Cts = null; } disposed = true; }
public void Dispose() { if (IsDisposed) { return; } Cancel(); IsDisposed = true; lock (disposing) { Cts.Dispose(); } }
public async ValueTask ConnectAsync(Uri url, CancellationToken token) { ThrowIfDisposed(); _limboCts?.Cancel(); _limboCts?.Dispose(); _limboCts = new Cts(); _ws?.Dispose(); _ws = _webSocketClientFactory.CreateClient(); if (_supportsZLib) { _receiveZLibStream?.Dispose(); _receiveZLibStream = _createZLibStream(_receiveStream); } await _ws.ConnectAsync(url, token).ConfigureAwait(false); }
private async void OnSearchTextChangedEvent(object sender, EventArgs e, object paramaters) { var model = (CustomerManagementPageViewModel)ParentsModel; if (model.IsDataGridLoading) { if (Cts != null) { Cts.Cancel(); } } model.IsDataGridLoading = true; if (customerDGCache == null) { customerDGCache = (DataGrid)((object[])paramaters)[0]; } TextBox ctrl = (TextBox)sender; await Task.Delay(100); if (Cts == null) { Cts = new CancellationTokenSource(); } var ct = Cts.Token; try { await Task.Delay(model.DelayTextChangedHandler, ct); customerDGCache.Items.Filter = new Predicate <object>(customer => FilterCustomerList(customer as tblCustomer, ctrl.Text)); model.IsDataGridLoading = false; } catch (OperationCanceledException ex) { if (Cts != null) { Cts.Dispose(); } Cts = null; } }
// Import the Footnotes table from csv to SQL server /// <summary> /// Starts the import. /// </summary> async public override void StartImport() { base.StartImport(); try { if (DataContextObject.DatasetItem.IsReImport) { using (var session = DataContextObject.Provider.SessionFactory.OpenStatelessSession()) { using (var trans = session.BeginTransaction()) { var query = string.Format("Delete from [{0}] where Dataset_Id={1}", DataContextObject.TargetType.EntityTableName(), DataContextObject.DatasetItem.Id); session.CreateSQLQuery(query).ExecuteUpdate(); trans.Commit(); } } } await ImportFileAsync(Cts.Token); // WPF CommandManager periodically calls IsValid to see if the Next/Done button should be enabled. // In multi-threaded wizard steps, IsValid returns the value of the Done flag. Call InvalidateRequerySuggested here // on the UI thread after setting the Done flag to force WPF to call IsValid now so the Next/Done button will become enabled. //Application.Current.DoEvents(); CommandManager.InvalidateRequerySuggested(); } catch (OperationCanceledException) { ImportCompleted(false); MessageBox.Show(AppendLog("Import cancelled.")); } finally { Cts.Dispose(); } }
public async ValueTask ConnectAsync(Uri url, CancellationToken token) { ThrowIfDisposed(); _limboCts?.Cancel(); _limboCts?.Dispose(); _limboCts = new Cts(); _ws?.Dispose(); _ws = _webSocketClientFactory.CreateClient(); if (_supportsZLib) { _receiveZLibStream?.Dispose(); _receiveZLibStream = #if NET5_0 CreateZLibStream(_receiveStream); #else new ZLibStream(_receiveStream, CompressionMode.Decompress, true); #endif } await _ws.ConnectAsync(url, token).ConfigureAwait(false); }
public void Reset() { lock (this) { _resetCts?.Cancel(); _resetCts?.Dispose(); var currentCount = _semaphore.CurrentCount; var releaseCount = _limit - currentCount; try { if (releaseCount != 0) { _semaphore.Release(releaseCount); _logger.LogDebug("Reset the semaphore: {0} -> {1}.", currentCount, _limit); } } finally { _isResetting = false; } } }
public ValueTask CloseAsync(CancellationToken cancellationToken = default) { _cts?.Cancel(); _cts?.Dispose(); _socket.Close(); return(default);
public void Dispose( ) { Cts?.Dispose( ); }
public void Dispose() { Cts.Cancel(); Cts.Dispose(); }
/// <summary> /// Destructs the ThreadBase object. Calls Dispose. /// </summary> //~ThreadBase() //{ // Dispose(); //} /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> public virtual void Dispose() { Cancel(); Cts.Dispose(); //Cts = null; }
/// <inheritdoc/> public virtual void Dispose() { _cts?.Cancel(); _cts?.Dispose(); }
/// <inheritdoc/> public void Dispose() { _cts.Cancel(); _cts.Dispose(); GC.SuppressFinalize(this); }
/// <inheritdoc/> public void Dispose() { _cts.Cancel(); _cts.Dispose(); }