3

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?

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • [No](https://msdn.microsoft.com/library/35st9aw1(v=vs.110).aspx). From Docs: *Use WaitForStatus to suspend an application's processing until the service has reached the required status.* Thats all. – makadev Oct 06 '16 at 10:57
  • @makadev Make that an answer then, and I'll accept. – ProfK Oct 06 '16 at 11:28
  • What's with the down-vote, little man? I didn't know if *required status* meant the one in the call to `WaitForStatus`, or one in a prior status setting call. – ProfK Oct 06 '16 at 15:02

1 Answers1

5

No.

From MSDN Documentations: Use WaitForStatus to suspend an application's processing until the service has reached the required status.

Thats all, it only suspends the calling thread and polls the status - as mentioned in the Documentation - every some 250ms until either Service State or Timeout is reached.

makadev
  • 1,034
  • 15
  • 26