public void CancelPendingUpdates_PendingTasksAreCanceled() { var scheduler = new TaskDelayScheduler(TimeSpan.FromMilliseconds(50), new IProjectThreadingServiceMock(), CancellationToken.None); bool taskRan = false; var task1 = scheduler.ScheduleAsyncTask((ct) => { taskRan = true; int count = 50; while (count != 0) { ct.ThrowIfCancellationRequested(); Thread.Sleep(20); --count; } return(Task.CompletedTask); }); scheduler.CancelPendingUpdates(); try { task1.Task.Wait(); Assert.False(taskRan); } catch (OperationCanceledException) { } }
public void CancelPendingUpdates_PendingTasksAreCanceled() { var scheduler = new TaskDelayScheduler(TimeSpan.FromMilliseconds(50), new IProjectThreadingServiceMock(), CancellationToken.None); bool taskRan = false; var task1 = scheduler.ScheduleAsyncTask((ct) => { taskRan = true; return(Task.CompletedTask); }); scheduler.CancelPendingUpdates(); task1.Task.Wait(); Assert.False(taskRan); }