public void CancelAllOpenTasks() { if (!Cancel.IsCancellationRequested) { Cancel.Cancel(); } }
public async Task SleepAsync() { Interlocked.CompareExchange(ref _running, 2, 1); // If running, make it stopping. Cancel?.Cancel(); while (Interlocked.CompareExchange(ref _running, 3, 0) == 2) { await Task.Delay(50); // wait for Start() loop to Cancel } Cancel?.Dispose(); Cancel = null; }
public async Task StopAsync() { Synchronizer.ResponseArrived -= Synchronizer_ResponseArrivedAsync; if (IsRunning) { Interlocked.Exchange(ref _running, 2); } Cancel?.Cancel(); while (IsStopping) { Task.Delay(50).GetAwaiter().GetResult(); // DO NOT MAKE IT ASYNC (.NET Core threading brainfart) } Cancel?.Dispose(); using (await MixLock.LockAsync()) { await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray()); State.DisposeAllAliceClients(); IEnumerable <TxoRef> allCoins = State.GetAllQueuedCoins(); foreach (var coinReference in allCoins) { try { var coin = State.GetSingleOrDefaultFromWaitingList(coinReference); if (coin is null) { continue; // The coin isn't present anymore. Good. This should never happen though. } await DequeueCoinsFromMixNoLockAsync(coin.GetTxoRef()); } catch (Exception ex) { Logger.LogError <CcjClient>("Couldn't dequeue all coins. Some coins will likely be banned from mixing."); if (ex is AggregateException) { var aggrEx = ex as AggregateException; foreach (var innerEx in aggrEx.InnerExceptions) { Logger.LogError <CcjClient>(innerEx); } } else { Logger.LogError <CcjClient>(ex); } } } } }
public void Stop() { try { Cancel?.Cancel(); Skip?.Cancel(); playing = null; } catch (Exception) { } }
public async Task StopAsync() { Synchronizer.ResponseArrived -= Synchronizer_ResponseArrivedAsync; Interlocked.CompareExchange(ref _running, 2, 1); // If running, make it stopping. Cancel?.Cancel(); while (Interlocked.CompareExchange(ref _running, 3, 0) == 2) { await Task.Delay(50); } Cancel?.Dispose(); Cancel = null; using (await MixLock.LockAsync()) { await DequeueSpentCoinsFromMixNoLockAsync(); State.DisposeAllAliceClients(); IEnumerable <TxoRef> allCoins = State.GetAllQueuedCoins(); foreach (var coinReference in allCoins) { try { var coin = State.GetSingleOrDefaultFromWaitingList(coinReference); if (coin is null) { continue; // The coin isn't present anymore. Good. This should never happen though. } await DequeueCoinsFromMixNoLockAsync(coin.GetTxoRef(), "Stopping Wasabi."); } catch (Exception ex) { Logger.LogError <CcjClient>("Couldn't dequeue all coins. Some coins will likely be banned from mixing."); if (ex is AggregateException) { var aggrEx = ex as AggregateException; foreach (var innerEx in aggrEx.InnerExceptions) { Logger.LogError <CcjClient>(innerEx); } } else { Logger.LogError <CcjClient>(ex); } } } } }
private async Task StopCommandAsync() { Cancel?.Cancel(); Cancel = null; }