I have a .NET 4 app running on Windows Server 2008 R2 which I use a separate running process to manage its life cycle (i.e., detect turn on / unexpected shutdown / reboot). This works fine for typical conditions. However, when the application throws an exception, Windows brings up the debug window offering to debug the application. I just want the application to crash, so the process runner can detect the crash and manage accordingly.
How do I allow an application to close on an exception?
Add a handler to the
Application.ThreadExceptionand in the handler, log the event, then exit nicely.Also, add an event handler to AppDomain.CurrentDomain.UnhandledException as well.
Unhandled Exceptions MSDN
Edit: removed bit about Handled flag.. thanks Alex