2010-12-17 31 views
12

は私が安全なハンドルが閉じられている診断説明ObjectDisposedExceptionが

メッセージと説明ObjectDisposedExceptionに当たっているC#アプリケーションを持っている「安全なハンドルが閉じられました」

これは、すぐに私が起動して起こります応用。

悲しいことに、スタックトレースは本当に役に立たない(下記参照)。ここでどの呼び出しが非同期的に試行されているかを判断する方法はありますか?

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 MSG、System.Runtime.Remoting.Messaging.IMessageSink replySink = {システム。 Runtime.Remoting.Messaging.AsyncResult})+ 0x279 bytes
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(システム。 Threading._ThreadPoolWaitCallback tpWaitCallBack)+ 0x53バイト
mscorlib.dll !System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(オブジェクト 状態)+ 0x59バイト

答えて

11

問題は私がusing(){}ブロックを使用したことが原因でした。

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

呼び出しスレッドが中断されると、使用ブロックはWaitHandle上でCloseを呼び出しています。

12

あなたはまだ別のスレッドによって使用されている何かを配置しています。

+0

ありがとうございます - 私は処分しているものと他のスレッドがまだそれを使用しているものを解決する方法はありますか? – mchr

+4

@mchr:Debug、Break at Function、 'System.Runtime.InteropServices.SafeHandle.Dispose'です。 – SLaks

関連する問題