public void CancelTest() { var task = new Monitor(); var count = 0; task.Execute(token => { while (count != 100) { count++; token.ThrowIfCancellationRequested(); Thread.Sleep(100); } }); Assert.True(task.IsRunning); task.Cancel(); Assert.True(task.IsCanceled); Assert.False(task.IsRunning); Assert.AreNotEqual(100, count); }