【发布时间】:2012-09-05 18:59:29
【问题描述】:
我遇到了一些从一些异步代码中得到的异常的问题。我不想阻塞我的线程,而
private async Task ThrowSomeExceptionAsync()
{
//Some long running process would go here...
throw new Exception();
}
这是我要调用并捕获异常的方法。我正在使用Application.UnhandledException 事件来捕获我的异常,但在这种情况下它没有被捕获。
我尝试等待返回的 Task 对象的 Exception 属性被填充,但在任务完成时会阻塞。
使用 ContinueWith 方法可以防止阻塞,但是从委托中抛出的任何异常都不会被 UndhandledException 事件捕获。
如何以异步方式执行此代码,但仍使用我的 UnhandledException 事件进行错误处理?我是否错过了有关该事件的一些基本概念?
【问题讨论】:
标签: .net asynchronous exception-handling microsoft-metro async-await