I can hookup to AppDomain.CurrentDomain.UnhandledException
to log exceptions from background threads, but how do I prevent them terminating the runtime?
AppDomain.CurrentDomain.UnhandledException += (sender, e2) =>
{
Thread.CurrentThread.Join();
};
But be careful, this code will freeze all the stack memory of the Thread and thread's managed object itself. However, if your application is in determined state (may be you threw LimitedDemoFunctionalityException or OperationStopWithUserMessageException) and you are not developing 24/7 application this trick will work.
Finally, I think MS should allow developers to override the logic of unhandled exceptions from the top of the stack.