Ray's playground

 

Item 37: Construct Parallel Algorithms with Exceptions in Mind(Effective C#)

Exceptions are complicated in any algorithm. Parallel tasks create more complications. The Parallel Task Library uses the AggregateException class to hold any and all exceptions thrown somewhere in the depths of your parallel algorithms. Once any of the background threads throws an exception, any other background operations are also stopped. Your best plan is to  try to ensure that no exceptions can be thrown from the code executing in your parallel tasks. Even so, other exceptions that you don’t expect may be thrown elsewhere. That means you must handle any AggregateException in the controlling thread that initiated all the background work.

posted on 2011-02-25 21:16  Ray Z  阅读(292)  评论(0编辑  收藏  举报

导航