I'm using the TPL (Task Parallel Library) in .NET 4.0. I want 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 what I want because this mechanism is not "centralized" enough.
Does anyone experience same problem at all or is it just me? Do you have any solution for this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…