Stop Service on Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have developed a Windows service in C# (inherited from System.ServiceProcess.ServiceBase) and, after the service has successfully started, when I catch an exception I'd like to write the code for the service to stop itself. Right now, when an exception occurs the service seems to halt but it still shows as "Started" in the Services window. Could someone please suggest the best way to stop the service so the "Started" doesn't appear

Thanks
 
The simplest solution to this is for your service to create a
ServiceController referring to itself and call its Stop method.


Mike001 said:
Hi,

I have developed a Windows service in C# (inherited from
System.ServiceProcess.ServiceBase) and, after the service has successfully
started, when I catch an exception I'd like to write the code for the
service to stop itself. Right now, when an exception occurs the service
seems to halt but it still shows as "Started" in the Services window. Could
someone please suggest the best way to stop the service so the "Started"
doesn't appear?
 
Back
Top