Tom*_*Tom 5 .net c# asynchronous exception httpwebrequest
System.Net.InternalException: System error.
at System.Net.HttpWebRequest.CheckWriteSideResponseProcessing()
at System.Net.ConnectStream.ProcessWriteCallDone(ConnectionReturnResult retur
nResult)
at System.Net.HttpWebRequest.WriteCallDone(ConnectStream stream, ConnectionRe
turnResult returnResult)
at System.Net.ConnectStream.CallDone(ConnectionReturnResult returnResult)
at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean abort
ing)
at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeSta
te)
at System.Net.ConnectStream.CloseInternal(Boolean internalCall)
at System.Net.HttpWebRequest.EndWriteHeaders_Part2()
at System.Net.HttpWebRequest.EndWriteHeaders(Boolean async)
at System.Net.HttpWebRequest.WriteHeadersCallback(WebExceptionStatus errorSta
tus, ConnectStream stream, Boolean async)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr u
serToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
Run Code Online (Sandbox Code Playgroud)
这被未处理的异常处理程序捕获。它只是偶尔发生,但会带来灾难性的后果。任何想法如何真正抓住这一章?
更新
现在很明显,这似乎只发生在 CPU 处于异常高负载的情况下。
如果这个异常是在 I/O 完成线程上抛出的,基本上没有您的任何干预,那么我会倾向于向Microsoft Connect开具票证。推理:您启动一个异步 I/O 操作,该操作会抛出异常,可能是由于线程池上的连接全部被删除而导致 - 您无法捕获该异常。这意味着异步操作期间连接断开可能会导致您的应用程序崩溃,而您对此无能为力。对我来说听起来像是框架中的一个错误。
临时解决方法可能是将 a 放在应用程序配置的部分<legacyUnhandledExceptionPolicy enabled="1"/>
中。<runtime>
这将恢复到 .NET 1.0/1.1 行为,其中在主线程之外的另一个线程上引发的异常不会导致应用程序崩溃。另请参阅:http ://msdn.microsoft.com/en-us/library/ms228965.aspx