Thursday, 10 November 2011

Parallel.ForEach operations and the CancellationToken

If you use the CancellationToken to enable cancellation during the parallel iteration of an enumerable, then you should note that each operation is given a chance to finish.  The OperationCanceledException is only thrown after all the threads have completed their unit of work.

You could monitor the cancellation token inside the units of work as well if you liked.