我得到以下异常:
Exception Type: System.InvalidOperationException
Exception Message: The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone).
Exception Stack: at System.Threading.SynchronizationContextSwitcher.Undo()
at System.Threading.ExecutionContextSwitcher.Undo()
at System.Threading.ExecutionContext.runFinallyCode(Object userData, Boolean exceptionThrown)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteBackoutCodeHelper(Object backoutCode, Object userData, Boolean exceptionThrown)
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.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
Exception Source: mscorlib
Exception TargetSite.Name: Undo
Exception HelpLink:
该应用程序是 Visual Studio 2005 (.Net 2.0) 控制台应用程序。它是一个用于多个 TCP/IP 连接的服务器,执行异步套接字读取和同步套接字写入。
在寻找答案时我遇到了这个帖子 http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/48b4a763-7387-46da-8fc2-3e885670f62c其中谈到了一个电话Application.Doevents()
我在我的代码中没有使用它。
我还发现这个帖子 http://social.msdn.microsoft.com/Forums/en-US/clr/thread/270504db-76c3-4b0e-8b98-1d0bd4ce0258其中有一项决议涉及Component
我也不在我的代码中使用它。该应用程序确实引用了我创建的包含自定义用户控件和组件的库,但应用程序并未使用它们。
问: 是什么原因导致这种情况发生以及如何防止这种情况再次发生?
或者一个更现实的问题:这个异常实际上意味着什么?在这种情况下如何定义“上下文”?
任何可以帮助我了解正在发生的事情的信息都将非常感激。