/// <summary> /// Waits for the given status the given time. /// </summary> /// <param name="state">The state.</param> /// <param name="timeout">The timeout.</param> /// <exception cref="TimeoutException">WaitForStatus</exception> public void WaitForStatus(Advapi32.ServiceCurrentState desiredStatus, TimeSpan timeout) { Advapi32.ServiceCurrentState serviceCurrentState = QueryServiceStatus().currentState; DateTime utcNow = DateTime.UtcNow; while (serviceCurrentState != desiredStatus) { if (DateTime.UtcNow - utcNow > timeout) { throw new TimeoutException("Service: WaitForStatus timeout."); } Thread.Sleep(250); serviceCurrentState = QueryServiceStatus().currentState; } }
/// <summary> /// Waits for status. /// </summary> /// <param name="desiredStatus">The desired status.</param> public void WaitForStatus(Advapi32.ServiceCurrentState desiredStatus) { WaitForStatus(desiredStatus, TimeSpan.MaxValue); }