I’m trying to stop a running service, with a console program I’ve made.
This is my code:
ServiceController sc = new ServiceController(ServiceName, ".");
sc.Stop();
I then wait for the service status, to turn into Stopped, but this never happens.
It seems to have StopPending and never goto Stopped.
When I check Services.msc, it is listed as stopped, and in the taskmanager, the process is gone.
Will it stay on Pending forever? Am I doing something wrong?
I have the code for the service aswell, if I need to modify something there.
You may try waiting after stopping the service:
The
WaitForStatusmethod will wait for the service to reach the specified status or for the specified time-out to expire before returning.