Currently I have a method like this:
private bool IsMyServiceRunning(string serviceName)
{
if (String.IsNullOrEmpty(serviceName))
throw new InvalidOperationException("ServiceName cannot be null or empty");
using (var service = new ServiceController(serviceName))
{
if (service.Status == ServiceControllerStatus.Running)
return true;
else
return false;
}
}
Is this the right way to use the ServiceController class?
The reason I ask is that all the examples I have seen do not call the Close() method when they're done using it. Are those bad examples or am I missing something?