1

I'm working on an unattended application that launches another process. It can have up to N instances of that process running in parallel.

When an unhandled exception is thrown, the "%APPNAME% stopped working" dialog is launched, and the process stays alive forever until someone clicks the Close button.

Is there any way to prevent this, or to know that it happened if nobody closes the dialog?

I wouldn't like to disable it system-wide (if there's an option); just in the process I am launching...

raven
  • 2,574
  • 2
  • 27
  • 49
  • 1
    maybe [this answer](http://stackoverflow.com/questions/1900013/how-to-configure-dr-watson-to-silently-dump-a-crashing-process-without-popping-u/1900152#1900152) could help you with a system wide setting. – Adrien Plisson Sep 20 '11 at 09:17
  • @AdrienPlisson, thanks for the info. Even if this is not what I need now, it's nice to have it at hand! – raven Sep 20 '11 at 09:25

1 Answers1

1

Handle the Unhandled exception handler in program.cs

AppDomain currentDomain = default(AppDomain);
currentDomain = AppDomain.CurrentDomain;
// Handler for unhandled exceptions.
currentDomain.UnhandledException += GlobalUnhandledExceptionHandler;

private static void GlobalUnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
       Exception ex = default(Exception);
       ex = (Exception)e.ExceptionObject;
       //Log and Trap exception

}

Read more here: http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx

A G
  • 21,087
  • 11
  • 87
  • 112