重新启动Windows事件日志服务会崩溃我自己的Windows服务

时间:2016-08-02 08:47:31

标签: c# crash windows-services event-log unhandled-exception

我有使用C#EventLog类(System.Diagnostics.EventLog)的Windows服务。当我重新启动Windows事件日志服务时,即使我没有同时写入日志,我自己的服务也会崩溃。我可以抓住异常 AppDomain.CurrentDomain.UnhandledException + = OnUnhandledException;  但它通过IsTerminating = True到达那里,然后服务崩溃。

我想这是因为EventLog类正在后台监听。我想找到一种方法来捕获这个异常,并保持我的Windows服务,但没有选择使用这个类,直到下一次它开始。

未处理异常的堆栈跟踪:

System.ComponentModel.Win32Exception: The interface is unknown
   at System.Diagnostics.EventLog.get_EntryCount()
   at System.Diagnostics.EventLog.CompletionCallback(Object context)
   at System.Diagnostics.EventLog.StaticCompletionCallback(Object context, Boolean wasSignaled)
   at System.Threading._ThreadPoolWaitOrTimerCallback.WaitOrTimerCallback_Context(Object state, Boolean timedOut)
   at System.Threading._ThreadPoolWaitOrTimerCallback.WaitOrTimerCallback_Context_f(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)

0 个答案:

没有答案