locked
How do I make a service fail? RRS feed

  • Question

  • I have written a service in VB.Net and I have successfully installed the service.  I've also gone into Administrative Tools / Services and looked at the properties of my service.  One of the tabs on the properties window is Recovery.  There you can set up what happens upon the first, second, or subsequent failure.  I want to reboot the computer after the first service failure. 

     

    In order to test this, I want my service to fail but I can't figure out how to do this.  I've tried implementing a timer with a stop command.  That just causes the JIT debugger to pop up.  I've also tried Me.Stop.  All that does is cause the service to stop...it does not cause a reboot. 

     

    How do I make my service fail so that windows will apply the actions in the Recovery tab?

     

    Clark

     

    Thursday, February 21, 2008 6:15 PM

Answers

  • Feng

     

    On my system, an unhandled system does not cause the service to fail even though in my simple test service, I have no error handling whatsoever.  When I toss an exception, I get no event log messages, no restarts of the service, nothing.  The service just continues to run as if nothing had happened.   

     

    I have found that either of the following statements cause what I want....

     

    System.Environment.Exit(0)

    System.Environment.FailFast("Shutting down service using FailFast")

     

    Clark

     

    Monday, February 25, 2008 3:04 PM

All replies

  • You can throw an unhandled exception.
    Friday, February 22, 2008 1:34 AM
  • Feng

     

    On my system, an unhandled system does not cause the service to fail even though in my simple test service, I have no error handling whatsoever.  When I toss an exception, I get no event log messages, no restarts of the service, nothing.  The service just continues to run as if nothing had happened.   

     

    I have found that either of the following statements cause what I want....

     

    System.Environment.Exit(0)

    System.Environment.FailFast("Shutting down service using FailFast")

     

    Clark

     

    Monday, February 25, 2008 3:04 PM