提问人:J4N 提问时间:8/28/2023 最后编辑:Peter CsalaJ4N 更新时间:8/28/2023 访问量:97
如何查找未观察到的任务异常的来源
How to find the source of an unobserved task exception
问:
在我们的 WPF 应用程序中,我们确实为未观察到的任务异常注册了一个事件处理程序:
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
使用以下方法:
private static void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs exceptionEventArgs)
{
_logger.Error(exceptionEventArgs.Exception, Properties.Resources.TaskExceptionsWereNotObserved);
exceptionEventArgs.SetObserved();
}
我确实得到了完整的堆栈跟踪:
System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (The I/O operation has been aborted because of either a thread exit or an application request.)
---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Net.Sockets.SocketReceiveFromResult>.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask`1.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of inner exception stack trace ---
但是我们的代码中似乎没有任何内容。
我的问题:
有没有办法添加更多调试信息以了解这是在哪里触发的?因为我甚至不确定异常发生在我们的代码中还是在外部库中。
答: 暂无答案
评论
AggregateException
SocketException
SocketException
System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request.
SocketException
async void