2010-12-17 29 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 味精,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)+ 0×28字節
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 bytes
mscorlib.dll !System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(對象 狀態)+ 0×59字節

回答

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 2010-12-17 17:57:10

+4

@mchr:調試,中斷函數,'System.Runtime.InteropServices.SafeHandle.Dispose'。 – SLaks 2010-12-17 17:58:17

相關問題