Let's explore canceling a task. Now that we know how to start one or more tasks and how to coordinate waiting on one or more of these tasks, what if something happens after we have started a group of tasks and we need to stop them?
Task cancellation is accomplished in the .NET framework by using cancellation tokens. The delegate used when running a task needs to have code to support cancelation and then any other code that needs to cancel a task can request cancelation of the task.
CancellationToken structure in .NET manages notification that an operation should be canceled. It has a property,
IsCancellationRequested, that you can use to see if a cancellation request has been issued. This structure is a member of the