This is related to a previous question.
What I’m trying to understand now is how come UI thread exceptions can be prevented from terminating the application while non-UI exceptions can’t be.
For reference, see this example.
Most importantly, what I would like to be able to do in that case is “silently” terminate the process–without displaying the Windows dialog box that asks whether I’d like to send an error report or not.
This is my AppDomain UnhandledExceptionHandler:
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
// Maybe do some logging here if allowed
}
catch
{
}
// then just terminate the application
Application.Exit();
}
UPDATE
In light of comments in this answer, I’d like to clarify that most importantly I’d like to find out more about the mechanism that enables the UI thread to have an early opportunity to catch unhandled exceptions via the Application.ThreadException mechanism. And whether such behavior could be implemented on a non-UI thread.
After doing some more searches on Google I found this very interesting explanation that was given to the same problem as described by Jeff Atwood on his blog.
However, I’m still interested in how the UI thread accomplishes the trick of allow you to have a catch-all handler for all UI thread exceptions.
Even more, I’m very interested in a way to disable the .NET JIT Debugging Dialog for my application only (without disabling it for the whole machine as seen here)