本文介绍了使用SocketAsyncEventArgs的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试将一些旧的BeginSend代码转换为SendAsync。我经常遇到以下异常: 无法应用已跨越AppDomains封送的上下文,这些上下文未通过Capture操作获取或已经是Set调用的参数。" 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态) System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError,Int32 bytesTransferred,SocketFlags flags)在System.Net .Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode,UInt32 numBytes,NativeOverlapped * nativeOverlapped) System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode,UInt32 numBytes,NativeOverlapped * pOVERLAP) 当我出现时,会发生这种情况做压力测试。在轻负载下,我从来没有看到它。 任何帮助都会受到赞赏! I'm trying to convert some of my old BeginSend code to SendAsync.  I frequently get the following exception:Cannot apply a context that has been marshaled across AppDomains, that was not acquired through a Capture operation or that has already been the argument to a Set call." at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)   at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)   at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)This happens when I am doing stress testing.  Under light load I never see it. Any help would be appreciated!推荐答案 事实证明只有在 UseOnlyOverlappedIO 设置为true。我正在做一些测试,以确保一切都能在旧机器上正常工作,并且我没有将它关闭以用于后续测试。也就是说,这是一个被修复的错误。It turns out that this exception is seen ONLY when UseOnlyOverlappedIO is set to true.  I was doing some testing to make sure everything would work fine on older machines, and I did not turn it off for subsequent testing.  That said, this a bug that be fixed. 这篇关于使用SocketAsyncEventArgs的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 04:16