ServiceController.WaitForStatus Method (ServiceControllerStatus)
Infinitely waits for the service to reach the specified status.
Assembly: System.ServiceProcess (in System.ServiceProcess.dll)
Use WaitForStatus to suspend an application's processing until the service has reached the required status.
The following example uses the ServiceController class to check whether the Alerter service is stopped. If the service is stopped, the example starts the service and waits until the service status is set to Running.