O'Reilly logo

C# Multithreaded and Parallel Programming by Rodney Ringler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Canceling a task

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.

Note

The 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 System.Threading ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required