Programmatically restart a service

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
 
R

Ray Cassick \(Home\)

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.
 
N

Norman Yuan

System.ServiceProcess.ServiceController class is what you want in your code
to start/stop a windows service.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top