tags:

views:

231

answers:

2

I am using system.timer in a windows service application (c#) and have added: AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyExceptionHandler);

To handle my exceptions, does this work in a Windows Service as it does not seem to work? Does nyone have any alternative ideas?

+1  A: 

Why do you have an unhandled exception in a service? What is the exception? Some exceptions have "special behavior" (and another link here for .NET 4 changes to corrupted state exceptions).

Also, what are you trying to do in the handler? Maybe the actions you're trying to do in the handler are what's limited when running as a service.

280Z28
+2  A: 

This mechanism will work to capture Unhandled Exceptions in any environment including Windows Services. However there are some limitations on what kind of exceptions can be handled in this way. For instance, a StackOverFlowException may be unhandled but do to it's nature you won't ever see it go through an UnhandledException handler.

Why do you think this is not working? Have you tried attaching to the process with a debugger , enabling first chance exceptions and see what is going on?

JaredPar