none
AppDomain.UnhandledException Event RRS feed

  • Question

  • I'm currently developing a fail-over system for a software suite which constantly gets updated to meet the moving needs of the customers. The components that are constantly changing are generally GUI portions of applications. These GUI portions are separate projects in a solution. A core project which doesn't get updated by design executes these smaller projects in their own processes at run-time. The core project monitors the processes for health purposes and can already handle situations where the processes become non-responsive by killing the process and starting it again. I'm currently working on these smaller projects for dealing with unhandled exceptions that require the application domain to terminate. At this point, the smaller projects:

    -Trap GUI thread exceptions at the application level, prepare an event log then attempt to recover the application state
    -Handle a non-gui thread exception, create a log and call Application.Exit() so the user doesn't have to close the application
    -The core project detects the Process.Exited event and restarts the smaller project which automatically exited after an unhandled exception in a non-gui thread

    What I'm trying to do at the moment is to suppress the OS dialog boxes that pop-up in the event of a fatal exception. Since I am already terminating the process within the problematic application, there's no need for user input to close it. This is especially annoying under Vista since it attempts to find a solution to the application problem.

    Is there a way I can configure the application domain to prevent these things? On my Windows 2003 SBS machine, I notice that problematic applications are automatically terminated to prevent OS instability and no error boxes are displayed. Is this exclusive OS behaviour or can I get the same effect through my applications on any OS the application runs on?

    Thanks guys.
    Sunday, July 12, 2009 10:03 AM

Answers

  • If error dialogs are shown, you are not properly trapping the exceptions.  The AppDomain.UnhandledException event handler and GUI trappers like Application.ThreadException should not be allowed to exit.  Log the error and immediately terminate the app with Environment.Exit().  Application.Exit() isn't good enough.


    Hans Passant.
    • Marked as answer by _Nobby_ Sunday, July 12, 2009 2:33 PM
    Sunday, July 12, 2009 2:11 PM
    Moderator

All replies

  • If error dialogs are shown, you are not properly trapping the exceptions.  The AppDomain.UnhandledException event handler and GUI trappers like Application.ThreadException should not be allowed to exit.  Log the error and immediately terminate the app with Environment.Exit().  Application.Exit() isn't good enough.


    Hans Passant.
    • Marked as answer by _Nobby_ Sunday, July 12, 2009 2:33 PM
    Sunday, July 12, 2009 2:11 PM
    Moderator
  • Environment.Exit() worked a treat. Thanks for that mate
    Sunday, July 12, 2009 2:33 PM