コード例 #1
0
 public void CancelAllOpenTasks()
 {
     if (!Cancel.IsCancellationRequested)
     {
         Cancel.Cancel();
     }
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: CcjClient.cs プロジェクト: adyshimony/WalletWasabi
        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);
                        }
                    }
                }
            }
        }
コード例 #4
0
 public void Stop()
 {
     try
     {
         Cancel?.Cancel();
         Skip?.Cancel();
         playing = null;
     }
     catch (Exception)
     {
     }
 }
コード例 #5
0
        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);
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: MainWindowVM.cs プロジェクト: khimalex/ShoeDryer
 private async Task StopCommandAsync()
 {
     Cancel?.Cancel();
     Cancel = null;
 }