Nearly every forum thread I have found on "catching unhandled exceptions in a service" seems to end up where I am. The supposed solution is the use of the AppDomain.CurrentDomain.UnhandledException event. But it doesn't work for someone, who
then asks why and gets no answer. Same for me; I can't get the event to happen. It's as if I need the ServiceProcess version of Application.SetUnhandledExceptionMode(), which doesn't exist.
For diagnosing this, I start a timer in a child object of the service and then throw an exception in the timer event handler. Simple enough to simulate the real situation. I have tried subscribing to the UnhandledException event in at least
a half dozen locations throughout the service, from the Program that runs ServiceBase.Run() to the constructor of the object that owns the Timer, but it never catches this exception. The VS debugger recognizes that the forced exception is unhandled and takes
me to the place where is thrown, letting me know it is an unhandled exception. Why doesn't my handler catch it? Running without the debugger, the exception throws, the timer thread crashes, the service continues merrily along, and nothing gets logged
anywhere. That is NOT the result I need.
What are the people for whom this works doing that I am not doing? How can I at least get the offe
View Complete Post