我有一个现有的方法如下:
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;
}
}
这是使用ServiceController类的正确方式吗?
我问这个问题的原因是,我看到的所有示例在使用完后都没有调用Close()方法。这些示例是错误的还是我漏掉了什么?
Dispose()
多次。规范说明Dispose()
必须能够被任意次数地调用。 - Andrew Barber