0

I am at designing phase and just converted from console to service. I want to know when out of memory exception happens in console it crashes out, but in case of window service seems like it is handled by service controller base class, and service still shows in running state.

So my question is:

How to make service stop?

I know if somehow I can catch the exception before service base class, it should be possible, but not sure.

Can someone provide the snippet? Also is it good practice to make service stop if some global unhandled exception occurs?

MKMohanty
  • 956
  • 7
  • 23
  • Are you sure that the service still running or it is running because of the service's _state_? When _state_ is equal to Automatic, then Windows automatic rerun it after crush. – Michael Jan 19 '16 at 04:22
  • 2
    *"Is it good practice to make service stop if some global unhandled exception occurs?"* - What else should you do? The service is no longer in a consistent state, and there is nothing reasonably to do. You might consider logging the exception, or writing a mini dump for diagnostics. But the service is toast. – IInspectable Jan 19 '16 at 04:26
  • Ya I agree that service should be in crashed state and issue should be resolved immediately. But I think as stated by VMA state is automatic and window rerun its after the crash. My question was how to prevent this programatically, and also @IInspectable your suggestion for writing mini dump is also nice. Is it possible to provide some link or snippet for this. – MKMohanty Jan 19 '16 at 05:23
  • 1
    http://stackoverflow.com/a/1135666/3297091 Check this out for automatic dump creation. – ThomasBecker Jan 19 '16 at 05:26

0 Answers0