I have a windows service that has a timer that fires a method every 30 seconds.
The method then calls thread.sleep() and when it finishes it calls thread.start();
All code in the method is wrapped in a try/catch except for the calls to the tread sleep/start.
For some reason the service stops working, but if I recycle it or set it to recycle upon a crash it works fine.
How can I diagnose the problem?
Is there other events like OnCrash or somethign that I can hook into to dig into the stack trace?
A windows service is just the same as a normal application, it’s just executed differently. So ask yourself if your normal app didn’t crash, but stopped working what could cause it? Lots of things spring to mind like locking issues, concurrency issues etc…
There is no OnCrash event though but what I do for Windows Services is put all logic in a seperate assembly with a simple start method and that way I can host it in a console application and do testing easily and moving to a windows service is also not too hard.
Your other option is to attach the Visual Studio debugger to the Windows service and debug as normal.