So, I have a windows service that will be started up once an hour. It will query some database tables and put data in other tables. After this is done, I would like to stop the service, that way, an hour later, it can be started again. I have tried:
this.Stop();
and
Service = new ServiceController(GlobalConstants.WindowsServiceName);
Service.Stop();
Service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 5, 0));
When I do the first, it runs, but I get an alert that it unexpectedly stopped. There are no errors in the Event Viewer. Everything went well, it just leaves a scary alert.
When I do the second, it stalls out and says it could not start the service and hit the timeout.
If I do not have any stop and just wait for the program, the service remains in the Started state.
GOAL
To stop the service without any warning type alerts or messages. It would be nice if the OnStop() was called as well.