我已经修改了一直在事先启动的工作Windows服务。添加System.Management引用后,它现在有时不会自动启动。我得到以下错误:为什么我的.NET Windows服务有时不会自动启动?
Service cannot be started. System.Runtime.InteropServices.COMException (0x80010002): Call was canceled by the message filter. (Exception from HRESULT: 0x80010002 (RPC_E_CALL_CANCELED))
我发现另一个帖子在SO上与某人有同样的问题。
Why won't my .Net Windows service start automatically after a reboot?
然而,所提出的解决办法是有它取决于已经启动的服务后,服务启动。然而,当我去依赖标签为我服务,我看到:
如果我只是用把线程睡眠的变通办法,还是有越来越这项服务的更合适的方式正确启动?发生这种情况是因为.NET在我的服务启动之前还没有启动?
感谢,
托梅克
编辑:我添加了一个try-catch语句来捕获异常。下面是我添加到我服务的OnStart()方法(这是异常被抛出哪里)代码
try
{
_watcher = new ManagementEventWatcher(query);
_watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
_watcher.Start();
}
catch (Exception ex)
{
EventLog.WriteEntry("Could not create Sleep/Resume watcher" + ex.Message);
}
的服务不从现在做起,但没有说我已经加入的功能。我是.NET新手,但是我从网上找到的示例中看到了守护程序代码,所以我非常肯定它是正确的。事件日志显示相同的异常:
Could not create Sleep/Resume watcher Call was canceled by the message filter. (Exception from HRESULT: 0x80010002 (RPC_E_CALL_CANCELED))
您也可以尝试在ServerFault.com上发布您的问题 – DOK 2010-03-08 20:50:28
由于您现在使用WMI,因此您应该等待Windows Management Instrumentation Service启动。尝试在安装时将其添加到相关服务。 – 2010-03-09 02:39:18