Monthly Archives: March 2012

Final Thoughts on CancellationTokenSource with Tasks and Parallel Operations

So, after running all of these tests and observing the different behaviors, I think I can provide a summary on what to expect when cancelling tasks and parallel operations in this way. I also think it is important to understand … Continue reading

Posted in Asynchrony, Parallel | Tagged , | 1 Comment

Understanding CancellationTokenSource with Parallel

CancellationTokenSource also works with Parallel.For, Parallel.ForEach, and Parallel LINQ much like with Task. The behavior is similar, but not the same. When starting a Parallel.For or ForEach, you can pass in a ParallelOptions object that contains the CancellationToken. When starting … Continue reading

Posted in Asynchrony, Parallel, Unit Tests | Tagged , , | 2 Comments

Understanding CancellationTokenSource with Tasks: Part 2

After some more testing and digging, I have discovered a way to keep Task cancellation behavior more consistent. In my previous post, I was allowing the Action within each Task to exit gracefully when it evaluated the IsCancellationRequested property of … Continue reading

Posted in Asynchrony, Unit Tests | Tagged , | 5 Comments

Understanding CancellationTokenSource with Tasks

I’ve been ramping up my knowledge of the new features coming in .NET 4.5 and C# 5 lately, namely the new features around asynchronous programming.  The Task class is at the heart of these new features, so I have been … Continue reading

Posted in Asynchrony, Unit Tests | Tagged , | 10 Comments