Created
May 8, 2013 03:06
-
-
Save Konard/5537912 to your computer and use it in GitHub Desktop.
ServiceControllerExtensions is a class containg extension-methods for System.ServiceProcess.ServiceController class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ServiceProcess; | |
using System.Threading; | |
namespace Helpers | |
{ | |
public static class ServiceControllerExtensions | |
{ | |
public static void StopAndWait(this ServiceController service) | |
{ | |
if (service.Status != ServiceControllerStatus.Stopped) | |
service.Stop(); | |
while (service.Status != ServiceControllerStatus.Stopped) | |
{ | |
Thread.Sleep(10); | |
service.Refresh(); | |
} | |
} | |
public static void StartAndWait(this ServiceController service) | |
{ | |
if (service.Status != ServiceControllerStatus.Running) | |
service.Start(); | |
while (service.Status != ServiceControllerStatus.Running) | |
{ | |
Thread.Sleep(10); | |
service.Refresh(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment