How to handle all unhandled exceptions when using Task Parallel Library?

Posted by Buu Nguyen on Stack Overflow See other posts from Stack Overflow or by Buu Nguyen
Published on 2010-04-25T05:40:13Z Indexed on 2010/04/25 5:43 UTC
Read the original article Hit count: 237

Filed under:
|
|
|

I'm using the TPL (Task Parallel Library) in .NET 4.0. I want to be able to centralize the handling logic of all unhandled exceptions by using the Thread.GetDomain().UnhandledException event. However, in my application, the event is never fired for threads started with TPL code, e.g. Task.Factory.StartNew(...). The event is indeed fired if I use something like new Thread(threadStart).Start().

This MSDN article suggests to use Task#Wait() to catch the AggregateException when working with TPL, but that is not I want because it is not "centralized" enough a mechanism.

Does anyone experience same problem at all or is it just me? Do you have any solution for this?

© Stack Overflow or respective owner

Related posts about TPL

Related posts about multithreading