I'm having troubles with handling exceptions in my application (WPF).
I'm using Tasks a lot, and I would like to have a global exception handler for all exceptions (even inside tasks).
I have tried multiple handlers:
AppDomain.CurrentDomain.UnhandledException
DispatcherUnhandledException
These works well for exceptions thrown in Application (not within a task)
For exceptions from tasks I tried to use
TaskScheduler.UnobservedTaskException
But this is being ran after a big delay. I think this is because of GarbageCollector, so I found one solution (which does not work too). This solution looks like this:
.ContinueWith(c =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
},TaskContinuationOptions.OnlyOnFaulted);
Could you please tell me how I should handle these exceptions? I would like to avoid handling it each time I run a tasks. A global handler is preferred for me.