Cancel() public method

Cancels the current task.
public Cancel ( ) : void
return void
示例#1
0
            public void AbortsPreviousAction()
            {
                AsyncTest.Run(async() =>
                {
                    var timer = new TaskTimer {
                        Delay = TimeSpan.FromMilliseconds(1)
                    };

                    bool actionInvoked = false;
                    timer.Start(() => Task.Factory.StartNew(() => actionInvoked = true));
                    timer.Cancel();

                    await TaskEx.Delay(20);

                    Assert.False(actionInvoked);
                });
            }
     public void AbortsPreviousAction()
     {
         AsyncTest.Run(async () =>
         {
             var timer = new TaskTimer { Delay = TimeSpan.FromMilliseconds(1) };
 
             bool actionInvoked = false;
             timer.Start(() => Task.Factory.StartNew(() => actionInvoked = true));
             timer.Cancel();
 
             await TaskEx.Delay(20);
 
             Assert.False(actionInvoked);
         });
     }