Exceptions and Parallel Loops

added by BlackWasp
9/7/2011 9:08:17 AM

200 Views

The sixth part of the Parallel Programming in .NET tutorial is the last instalment that examines the parallel loops. This article discusses how exceptions are thrown by code within a parallel loop and how they can be handled.


4 comments

dpeterson
9/7/2011 9:09:58 AM
Thanks for the article, none of the write-ups on the new parallel extensions that I've seen have covered exceptions.
How would you go about signaling the other threads that they should stop gracefully if you catch an aggregate exception? Or is there no way to tell scheduled iterations to stop/abort gracefully?

BlackWasp
9/8/2011 2:12:02 PM
You are most welcome :D

I'm going to write an article outside of the tutorial about this at some point. The best way in a loop is to use parallel loop state (also mentioned in the tutorial - look at the article about terminating loops early). There's a property named IsExceptional that you can look at to see if another parallel iteration has raised an exception. In long-runnning iterations you can check for this and terminate early using Stop.

dpeterson
9/8/2011 2:23:37 PM
Be sure to post it here when you're finished with it, I'm looking forward to reading it!

BlackWasp
9/9/2011 5:11:57 PM
Will do. You can also keep an eye on the RSS feed.