C# 超时已过期,尚未在Service manager中完成操作
我有一个windows服务管理器,我试图通过管理器停止服务。但是我得到了一个例外:C# 超时已过期,尚未在Service manager中完成操作,c#,.net,windows-services,C#,.net,Windows Services,我有一个windows服务管理器,我试图通过管理器停止服务。但是我得到了一个例外: Time out has expired and the operation has not been completed private static void StopService() { if (!IsInstalled()) return; try { CFEServiceController c = new CF
Time out has expired and the operation has not been completed
private static void StopService()
{
if (!IsInstalled()) return;
try
{
CFEServiceController c = new CFEServiceController();
c.StopService(ServiceName, 500);
}
catch (Exception ex)
{
Console.WriteLine("Error in Stop service " + ex.Message);
}
}
以及:
问题在于:
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
这是因为您的服务没有在
超时时间内停止。您应该将超时设置得更高,或者根本不设置超时。您也可以尝试打开
“事件查看器”->“Windows日志”->“应用程序”
如果如@gleng所回答的那样,增加/取消设置超时次数没有帮助,则可能会出现错误级别的消息,为您提供线索
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);