Short answer: you can cancel waiting tasks through the corresponding CancellationToken created by the CancellationTokenSource. Here is an example.
var tokenSource = new CancellationTokenSource(); var task = Task.Factory.StartNew(() => { for (int i = 0; i < 10; i++) { if (tokenSource.IsCancellationRequested) {
Everything is a little different when you are dealing with several tasks. First, you need to know when you cancel a task, will other tasks be performed? If so, you need to create different undo markers for different tasks and adjust the undo yourself. Otherwise, they can use the same cancellation token. Different requirements lead to different cancellation processing policies.
Danny chen
source share