I'm using ServiceController.WaitForStatus
for the first time to limit time wasted on trying to start services that won't start. My assumption is to use it like this:
var sc = new ServiceController(_monitoredService);
var seconds = _startWaitTimeout / 1000;
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 0, seconds));
if (sc.Status != ServiceControllerStatus.Running)
{
_logger.Warn($"'{_monitoredService}' did not start within {seconds} seconds.");
}
Then a little devil on my shoulder suggested that WaitForStatus
might take it upon itself to attempt to set the status before waiting. Does it?