Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何捕获此信号器异常_C#_Asp.net_Signalr_Async Await - Fatal编程技术网

C# 如何捕获此信号器异常

C# 如何捕获此信号器异常,c#,asp.net,signalr,async-await,C#,Asp.net,Signalr,Async Await,我有一个ASP.NET Web Api,它使用信号器与移动客户端进行实时数据通信。一切正常,但我在跟踪日志中看到异常,似乎无法捕获或处理此异常: Application: 2014-05-20T03:24:57 PID[2088] Warning SignalR exception thrown by Task: System.AggregateException: One or more errors occurred. ---> System.Web.HttpExceptio

我有一个ASP.NET Web Api,它使用信号器与移动客户端进行实时数据通信。一切正常,但我在跟踪日志中看到异常,似乎无法捕获或处理此异常:

Application: 2014-05-20T03:24:57  PID[2088] Warning     SignalR exception thrown by Task: System.AggregateException: One or more errors occurred. ---> System.Web.HttpException: The remote host closed the connection. The error code is 0x800704CD.
Application:    at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
Application:    at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
Application:    at System.Web.HttpResponse.Flush(Boolean finalFlush, Boolean async)
Application:    at System.Web.HttpResponse.Flush()
Application:    at System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
Application:    at System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
Application:    at Microsoft.Owin.Host.SystemWeb.CallStreams.OutputStream.Write(Byte[] buffer, Int32 offset, Int32 count)
Application:    at Microsoft.AspNet.SignalR.Owin.ServerResponse.Write(ArraySegment`1 data)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BinaryTextWriter.<.ctor>b__4(ArraySegment`1 data, Object state)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(Byte[] byteBuffer, Boolean flushEncoder)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(Boolean flushEncoder)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.Flush()
Application:    at Microsoft.AspNet.SignalR.Transports.ServerSentEventsTransport.PerformKeepAlive(Object state)
Application:    at Microsoft.AspNet.SignalR.Transports.ServerSentEventsTransport.<KeepAlive>b__0(Object state)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.TaskQueue.<Enqueue>b__1(Func`2 next, Object nextState)
Application:    at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod[T1,T2](Func`3 func, T1 arg1, T2 arg2)
Application:    --- End of inner exception stack trace ---
Application: ---> (Inner Exception #0) System.Web.HttpException (0x800704CD): The remote host closed the connection. The error code is 0x800704CD.
Application:    at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
Application:    at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
Application:    at System.Web.HttpResponse.Flush(Boolean finalFlush, Boolean async)
Application:    at System.Web.HttpResponse.Flush()
Application:    at System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
Application:    at System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
Application:    at Microsoft.Owin.Host.SystemWeb.CallStreams.OutputStream.Write(Byte[] buffer, Int32 offset, Int32 count)
Application:    at Microsoft.AspNet.SignalR.Owin.ServerResponse.Write(ArraySegment`1 data)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BinaryTextWriter.<.ctor>b__4(ArraySegment`1 data, Object state)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(Byte[] byteBuffer, Boolean flushEncoder)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(Boolean flushEncoder)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.Flush()
Application:    at Microsoft.AspNet.SignalR.Transports.ServerSentEventsTransport.PerformKeepAlive(Object state)
Application:    at Microsoft.AspNet.SignalR.Transports.ServerSentEventsTransport.<KeepAlive>b__0(Object state)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.TaskQueue.<Enqueue>b__1(Func`2 next, Object nextState)
Application:    at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod[T1,T2](Func`3 func, T1 arg1, T2 arg2)<---
应用程序:2014-05-20T03:24:57 PID[2088]任务引发的警告信号异常:System.AggregateException:发生一个或多个错误。-->System.Web.HttpException:远程主机已关闭连接。错误代码为0x800704CD。
应用程序:在System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32结果,布尔值)
应用程序:在System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()中
应用程序:位于System.Web.HttpResponse.Flush(布尔finalFlush,布尔异步)
应用程序:在System.Web.HttpResponse.Flush()上
应用程序:位于System.Web.HttpWriter.WriteFromStream(字节[]数据,Int32偏移量,Int32大小)
应用程序:在System.Web.HttpResponseStream.Write(字节[]缓冲区,Int32偏移量,Int32计数)
应用程序:位于Microsoft.Owin.Host.SystemWeb.CallStreams.OutputStream.Write(字节[]缓冲区、Int32偏移量、Int32计数)
应用程序:位于Microsoft.AspNet.signal.Owin.ServerResponse.Write(ArraySegment`1数据)
应用程序:位于Microsoft.AspNet.signal.Infrastructure.BinaryTextWriter.b__4(ArraySegment`1数据,对象状态)
应用程序:位于Microsoft.AspNet.signal.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(字节[]byteBuffer,布尔flushEncoder)
应用程序:位于Microsoft.AspNet.signal.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(布尔flushEncoder)
应用程序:位于Microsoft.AspNet.signal.Infrastructure.BufferTextWriter.Flush()上
应用程序:位于Microsoft.AspNet.signal.Transports.ServerSentEventsTransport.PerformKeepAlive(对象状态)
应用程序:位于Microsoft.AspNet.signar.Transports.ServerSentEventsTransport.b_0(对象状态)
应用程序:位于Microsoft.AspNet.signal.Infrastructure.TaskQueue.b__1(Func`2下一步,对象下一步状态)
应用程序:位于Microsoft.AspNet.signal.TaskAsyncHelper.FromMethod[T1,T2](Func`3 Func,T1 arg1,T2 arg2)
应用程序:---内部异常堆栈跟踪的结束---
应用程序:-->(内部异常#0)System.Web.HttpException(0x800704CD):远程主机已关闭连接。错误代码为0x800704CD。
应用程序:在System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32结果,布尔值)
应用程序:在System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()中
应用程序:位于System.Web.HttpResponse.Flush(布尔finalFlush,布尔异步)
应用程序:在System.Web.HttpResponse.Flush()上
应用程序:位于System.Web.HttpWriter.WriteFromStream(字节[]数据,Int32偏移量,Int32大小)
应用程序:在System.Web.HttpResponseStream.Write(字节[]缓冲区,Int32偏移量,Int32计数)
应用程序:位于Microsoft.Owin.Host.SystemWeb.CallStreams.OutputStream.Write(字节[]缓冲区、Int32偏移量、Int32计数)
应用程序:位于Microsoft.AspNet.signal.Owin.ServerResponse.Write(ArraySegment`1数据)
应用程序:位于Microsoft.AspNet.signal.Infrastructure.BinaryTextWriter.b__4(ArraySegment`1数据,对象状态)
应用程序:位于Microsoft.AspNet.signal.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(字节[]byteBuffer,布尔flushEncoder)
应用程序:位于Microsoft.AspNet.signal.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(布尔flushEncoder)
应用程序:位于Microsoft.AspNet.signal.Infrastructure.BufferTextWriter.Flush()上
应用程序:位于Microsoft.AspNet.signal.Transports.ServerSentEventsTransport.PerformKeepAlive(对象状态)
应用程序:位于Microsoft.AspNet.signar.Transports.ServerSentEventsTransport.b_0(对象状态)
应用程序:位于Microsoft.AspNet.signal.Infrastructure.TaskQueue.b__1(Func`2下一步,对象下一步状态)

应用程序:在Microsoft.AspNet.signal.TaskAsyncHelper.FromMethod[T1,T2](Func`3 Func,T1 arg1,T2 arg2)上,您应该能够通过
HttpApplication捕捉到它。错误
,更多详细信息如下:


但是我很惊讶,你的
捕获
块都没有被触发。您确定正在包装每个
任务吗?您可能想尝试类似于
task.WithObservation()
from.

的操作。您可以尝试:
Application.ThreadException+=new ThreadExceptionEventHandler(ErrorHandlerForm.Form1\u UIThreadException);//设置未处理的异常模式以强制所有Windows窗体错误通过//我们的处理程序。Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);//将用于处理非UI线程异常的事件处理程序添加到事件中。AppDomain.CurrentDomain.UnhandledException+=新的UnhandledExceptionEventHandler(CurrentDomain\u UnhandledException)
TaskScheduler.UnobservedTaskeException
根本无法捕获异常?TaskScheduler.UnobservedTaskeException无法捕获异常…荷兰男子--是否可以在ASP.NET Web Api项目中使用Application.ThreadException?谢谢。我尝试了HttpApplication.Error,它没有捕获任何内容,但我仍在处理您的任务。WithObservation()建议。这个链接让我找到了你的其他几篇文章——都非常好,从中学习了很多。@Ender2050,如果这有帮助的话,我很高兴。我仍在努力解决这个问题。再次感谢您迄今为止的帮助-从您的帖子中学到了很多。@Ender2050,您可以试着首先抓住它。这不会解决问题,但可能有助于故障排除。此错误是间歇性的,因此我不确定-但我认为我可以使用您在第二个链接中概述的方法来解决此问题。非常有帮助,再次谢谢你。