Category Archives: Unit Tests

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