本文介绍了如何调试“安全手柄已经关闭”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承的代码不断崩溃,出现以下错误(根本没有更改):

Code which I have inherited keeps crashing out rather powerfully with the following error (not changed at all):

System.ObjectDisposedException: Safe handle has been closed
   at Microsoft.Win32.UnsafeNativeMethods.GetOverlappedResult(
          SafeFileHandle hFile, NativeOverlapped* lpOverlapped,
          Int32& lpNumberOfBytesTransferred, Boolean bWait)
   at System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent()
   at System.Threading.ThreadHelper.ThreadStart_Context(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.ThreadHelper.ThreadStart()

以前的开发人员添加了一个。

This is only being caught as the previous developers added a AppDomain.UnhandledException Event.

如果我删除它,应用程序只是崩溃了一个Dr Watson消息(发送反馈等...)而不是通常的.NET对话框(使用continue选项和堆栈跟踪)。

If I remove it, the application just crashes out with a Dr Watson message (send feedback etc...) and not the usual .NET dialog (with the continue option and stack trace).

我已经检查过,与

我如何去寻找这个原因问题,看起来,从堆栈跟踪,不是在应用程序的代码?

How do I go about trying to find the cause of this issue, as it appears, from the stack trace, not to be in code of the application?

推荐答案

从系统.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent()和Microsoft.Win32.UnsafeNativeMethods被引用我会危害你有一个内部线程访问端口的COM组件,例如用于串行或TCP / IP数据。

From the fact that System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent() and Microsoft.Win32.UnsafeNativeMethods are referred to I would hazard that you have a COM component that has internal threads accessing a port e.g. for serial or TCP/IP data.

看起来线程在启动序列期间会抛出异常。可能是尝试访问不可用或不起作用的端口。这样就失败了,异常也没有被处理,从而传递代码。

It would look like the thread throws an exception during it's start sequence. Possibly it is trying to access an unavailable or nonexistant port. This fails and the exception is not handled and thus propogates back through the code.

尝试从UnhandledException事件中记录更多的信息,以了解这个可能开始的位置来自。

Trying logging more information from the UnhandledException Event in order to get an idea of where this may start from.

这篇关于如何调试“安全手柄已经关闭”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 13:53