Unhandled exception handling
For a "server in a closet", you can simply turn off the
default debugger
dialog. You can do this on a Machine-wide, User-wide, or
process-wide
basis. The machine-wide and user-wide settings are controlled
by:
HKLM\Software\Microsoft\COMPlus\DbgJitDebugLaunchSetting
HKCU\Software\Microsoft\COMPlus\DbgJitDebugLanuchSetting
and the process wide one by the environment
variable:
COMPLUS_DbgJitDebugLaunchSetting
The values here are:
0 - ask
1 - never attach a
debugger
2 - always attach a
debugger
Set it to 1, and there will be no system-provided
dialog.
Also
this:
Personally, I prefer to limit the scope of
this kind of setting to per-process (specifically, mine :-), so I
go with the environment variable approach. The only glitch is that,
there's not managed way to adjust process-wide environment
variables (it violates the appdomain isolation story), so you have
to resort to p/invoke. But if you're writing a service, then you're
going to have the necessary perms, and this kind of setting makes
sense anyways.
\// Declare this somewhere:
[DllImport("kernel32.dll")]
static extern bool SetEnvironmentVariable(string varName, string
varValue);
\// Do something like this during the service's initial
startup:
SetEnvironmentVariable("COMPLUS_DbgJitDebugLaunchSetting",
"1");
AppDomain.CurrentDomain.UnhandledException +=
new
UnhandledExceptionEventHandler(OnUnhandledException);