Programmatically restart a service

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

Guest

Dear all,

I wrote a service by C# but I found the service is not quite stable. I want
to add some code that refresh or restart the service itself for a fixed
period. Does anyone know how to programmatically restart a service itself?
Or I need a separate process to restart my service?

Thanks for any help.

Tedmond
 
Depending on the OS you are using, take a look at the service properties. In
XP there is a tab called recovery where you can define some failure and
restart properties.

Might be able to take care of your issue without writing any more code.

....but mind you this is not a solution for an unstable service. Only a
workaround.
 
System.ServiceProcess.ServiceController class is what you want in your code
to start/stop a windows service.
 
Back
Top