C# InvalidOperationException:撤消操作遇到的上下文与相应的Set操作中应用的上下文不同
我得到了以下例外:C# InvalidOperationException:撤消操作遇到的上下文与相应的Set操作中应用的上下文不同,c#,sockets,asynchronous,console-application,C#,Sockets,Asynchronous,Console Application,我得到了以下例外: 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 t
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连接的服务器,执行异步套接字读取和同步套接字写入
在寻找答案的过程中,我遇到了一个关于调用Application.Doevents()
的问题,我在代码中没有用到这个问题
我还发现了一个与组件相关的解析,我在代码中也没有使用它。应用程序确实引用了我创建的包含自定义用户控件和组件的库,但应用程序没有使用它们
问题:是什么导致了这种情况的发生,我如何防止这种情况再次发生?
或者一个更现实的问题:这个例外实际上意味着什么?在这种情况下,“上下文”是如何定义的
任何能帮助我理解正在发生的事情都将不胜感激。上下文称为“线程上下文”,与您的代码没有任何关系。
但是,这是.net的内部问题,可能仅限于测试版