Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 超时已过期,尚未在Service manager中完成操作_C#_.net_Windows Services - Fatal编程技术网

C# 超时已过期,尚未在Service manager中完成操作

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

我有一个windows服务管理器,我试图通过管理器停止服务。但是我得到了一个例外:

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);