Leonardo,
A Service can't easily restart itself, as most Windows Services only have a
single Service (a class derived from ServiceBase) in the executable (see
below). As soon as this single Service is stopped the executable is unloaded
from memory, hence your WaitForStatus is the last statement executed. Which
I fine is actually a good thing as it ensures that the entire Service is
flushed and the service's app.config file is reread.
I would consider adding a second service to the same executable, to prevent
the executable from being unloaded, which unfortunately will also prevent
the service's app.config from being reloaded.
Alternatively I would consider creating a second service in a second
executable, that is able to use your statements to restart the first. This
second one I would consider having a timer to periodically check for the
first.
Other possibilities might be to modify the Main routine generated as part of
the Windows Service (in the "Component Designer generated code" region) to
put the ServiceBase.Run statement in a loop to prevent the Main routine from
exiting, hence allowing the executable from unloading. Just remember!
depending on what you do in the Main routine, it may prevent your executable
from being unloaded!
Hope this helps
Jay
"Leonardo Curros" <jj***@mixmail.com> wrote in message
news:3f**************************@posting.google.c om...
Hello,
I would like to know what's the best way to restart one service. I
would like to do it from the service itself. Is this possible?
I try it with
ServiceController.stop()
ServiceController.WaitForStatus(ServiceControllerS tatus.Stopped)
ServiceController.start()
but doesn´t works. It seems waitforstatus instruction is the last
instruction executed.
Thanks in advance