诊断的ObjectDisposedException"安全手柄已经关闭" [英] Diagnose ObjectDisposedException "Safe handle has been closed"

查看:273
本文介绍了诊断的ObjectDisposedException"安全手柄已经关闭"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被击中的消息




安全手柄已经关闭

$ B $一个的ObjectDisposedException C#应用程序b

这会发生,只要我启动应用程序。



不幸的是堆栈跟踪是非常无益的(见下面)。有没有什么办法,我确定正在试图异步这里什么叫?



请问DoAsyncCall()真的意味着一个异步方法调用?




mscorlib程序。 dll的!System.Threading.EventWaitHandle.Set()+ 0xe字节结果
mscorlib.dll中!System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(System.Runtime.Remoting.Messaging.IMessage
MSG)+ 0x12f字节结果
mscorlib.dll中!System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(System.Runtime.Remoting.Messaging.IMessage
味精,System.Runtime.Remoting.Messaging .IMessageSink replySink =
{} System.Runtime.Remoting.Messaging.AsyncResult)+ 0x279字节结果
mscorlib.dll中!System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall()
+ 0x32字节mscorlib.dll中!System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(对象
O)+ 0x28字节结果
mscorlib.dll中!System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(对象
态)+值为0x2F字节结果
mscorlib.dll中!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
的ExecutionContext,System.Threading.ContextCallback回调,目标
状态)+ 0x6f字节结果
mscorlib.dll中!System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback
tpWaitCallBack)+ 0x53字节结果
mscorlib.dll中!系统.Threading._ThreadPoolWaitCallback.PerformWaitCallback(对象
状态)+ 0x59字节



解决方案

问题是我使用使用(){}块造成的。

 使用(WaitHandle的手柄= asyncResponse.AsyncWaitHandle)
{
asyncResponse.AsyncWaitHandle.WaitOne();
串响应= asyncRequest.EndInvoke(asyncResponse);
asyncResponse.AsyncWaitHandle.Close();
返回响应;
}

在调用线程被中断的使用块仍然呼吁的WaitHandle关闭


I have a C# application which is hitting an ObjectDisposedException with the message

Safe handle has been closed

This happens as soon as I launch the application.

Sadly the stack trace is really unhelpful (see below). Is there any way for me to determine what call was being attempted asynchronously here?

Does DoAsyncCall() really imply an async method call?

mscorlib.dll!System.Threading.EventWaitHandle.Set() + 0xe bytes
mscorlib.dll!System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(System.Runtime.Remoting.Messaging.IMessage msg) + 0x12f bytes
mscorlib.dll!System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(System.Runtime.Remoting.Messaging.IMessage msg, System.Runtime.Remoting.Messaging.IMessageSink replySink = {System.Runtime.Remoting.Messaging.AsyncResult}) + 0x279 bytes
mscorlib.dll!System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall() + 0x32 bytes mscorlib.dll!System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(object o) + 0x28 bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(object state) + 0x2f bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x6f bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback tpWaitCallBack) + 0x53 bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(object state) + 0x59 bytes

解决方案

The problem was caused by my use of a using(){} block.

    using (WaitHandle handle = asyncResponse.AsyncWaitHandle)
    {
      asyncResponse.AsyncWaitHandle.WaitOne();
      string response = asyncRequest.EndInvoke(asyncResponse);
      asyncResponse.AsyncWaitHandle.Close();
      return response;
    } 

When the calling thread is interrupted the using block is still calling Close on the WaitHandle.

这篇关于诊断的ObjectDisposedException"安全手柄已经关闭"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆