S
Simon
Hi all,
I'm having a problem creating a global exception handler in a windows
service that I'm making. Another poster suggested that the way to do
this was to use the CurrentDomain.UnhandledException event to catch and
deal with any exception that crops up. The problem is, when I try and
deliberately throw an exception in my services OnStart event handler,
nothing seems to happen. By that I mean, the
CurrentDomain_UnhandledException handler that I've created never seems
to be called.
Can anyone advise me if I'm doing this correctly? I've included the code
below. I just set up the event handler in the main method...
Thanks to anyone who can offer any help
Kindest Regards
Simon
static class Program {
static void Main() {
ServiceBase[] servicesToRun;
servicesToRun = new ServiceBase[] { new REMUSSchedulerService() };
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
ServiceBase.Run(servicesToRun);
}
static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e) {
TraceHelper.WriteLine(TraceLevel.Info, "Exception detected in
UnhandledException event handler: " + e.ExceptionObject.ToString());
}
}
I'm having a problem creating a global exception handler in a windows
service that I'm making. Another poster suggested that the way to do
this was to use the CurrentDomain.UnhandledException event to catch and
deal with any exception that crops up. The problem is, when I try and
deliberately throw an exception in my services OnStart event handler,
nothing seems to happen. By that I mean, the
CurrentDomain_UnhandledException handler that I've created never seems
to be called.
Can anyone advise me if I'm doing this correctly? I've included the code
below. I just set up the event handler in the main method...
Thanks to anyone who can offer any help
Kindest Regards
Simon
static class Program {
static void Main() {
ServiceBase[] servicesToRun;
servicesToRun = new ServiceBase[] { new REMUSSchedulerService() };
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
ServiceBase.Run(servicesToRun);
}
static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e) {
TraceHelper.WriteLine(TraceLevel.Info, "Exception detected in
UnhandledException event handler: " + e.ExceptionObject.ToString());
}
}