我有一个C#应用程序,它使用消息
命中ObjectDisposedException安全句柄已关闭
一旦我启动应用程序,就会发生这种情况。
可悲的是,堆栈跟踪真的没有用(见下文)。有什么方法可以让我确定在这里异步尝试的呼叫是什么?
DoAsyncCall()是否真的暗示异步方法调用?
mscorlib.dll!System.Threading.EventWaitHandle.Set()+ 0xe bytes
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 = {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字节
mscorlib.dll中!System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(对象 state)+ 0x2f bytes
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中!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(对象 状态)+ 0x59字节
答案 0 :(得分:14)
您正在处理仍由其他线程使用的内容。
答案 1 :(得分:14)
问题是由于我使用了using(){}块造成的。
using (WaitHandle handle = asyncResponse.AsyncWaitHandle)
{
asyncResponse.AsyncWaitHandle.WaitOne();
string response = asyncRequest.EndInvoke(asyncResponse);
asyncResponse.AsyncWaitHandle.Close();
return response;
}
当调用线程被中断时,using块仍然在WaitHandle上调用Close。
答案 2 :(得分:0)
使用API安全性,并拼写错误的“用户”:
[Authorize(Roles = "User")] // exception...
ObjectDisposedException:安全句柄已关闭
应该是:
[Authorize(Roles = "Users")] // works!
当组不存在时会抛出不同的错误,例如:
[Authorize(Roles = "SomeGroupThatDoesNotExist")]
Win32Exception:主域和可信域之间的信任关系失败