Canceling parallel work
In this section, we will work with some examples of canceling parallel operations. There are a few operations that fall into this realm. There are static parallel operations that are part of the
System.Threading.Tasks.Parallel class and there are PLINQ operations. Both of these types use a
CancellationToken property, as we used in our managed threading example in the previous section. However, handling the cancellation request is slightly different. Let’s look at an example to understand the differences.
Canceling a parallel loop
- Open the
CancelThreadsConsoleAppproject from the previous section.
- In the
ManagedThreadsExampleclass, create a new
ProcessTextParallelmethod with the following implementation:
public static void ProcessTextParallel...