.NET 4: Parallel Programming – Cancelling/Exception Handling with Task Parallel Library
There are lot of goodies in .NET 4 for Parallel Programming. There is even a separate dedicated section on it. The following picture from that section explains the four categories of improvement in Framework just for this.
I mentioned earlier that previously I used Abortable Threadpool to implement cancelling work under specific condition. With ThreadPool we never had an easy way to queue the batch of work, know when that batch is completed and do exception handling properly. Things have significantly improved with Task Parallel Library; which is integrated with ThreadPool and resolves all the issues I mentioned plus lot more. Here is small app that does cancelling the tasks after certain time out and investigates the exception if any thrown by the task!