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?