示例#1
0
 public void Cancelled0()
 {
     AsyncContext.Run(async() =>
     {
         await AssertEx.CompletesCanceledAsync(AsyncFactory.FromApm(BeginCancel0, End));
     });
 }
示例#2
0
 public void FromWaitHandle_CanceledBeforeTimeoutOrHandleSignalled_CompletesCanceled()
 {
     AsyncContext.Run(() => Task.Run(async() =>
     {
         var mre  = new ManualResetEvent(false);
         var cts  = new CancellationTokenSource();
         var task = AsyncFactory.FromWaitHandle(mre, Timeout.InfiniteTimeSpan, cts.Token);
         Assert.IsFalse(task.IsCompleted);
         cts.Cancel();
         await AssertEx.CompletesCanceledAsync(task);
     }));
 }
示例#3
0
        public void FromEvent1_AsyncEventCanceled_Cancels()
        {
            AsyncContext.Run(() => Task.Run(async() =>
            {
                var bgw = new BackgroundWorker();
                bgw.WorkerSupportsCancellation = true;
                bgw.DoWork += (_, args) =>
                {
                    while (!bgw.CancellationPending)
                    {
                        Thread.Sleep(100);
                    }
                    args.Cancel = true;
                };
                var task = AsyncFactory <RunWorkerCompletedEventArgs> .FromEvent(bgw, "RunWorkerCompleted");
                bgw.RunWorkerAsync();
                bgw.CancelAsync();

                await AssertEx.CompletesCanceledAsync(task);
            }));
        }