TPL歇上未处理的异常 [英] TPL Break on unhandled exceptions

查看:106
本文介绍了TPL歇上未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用异步 伺机以及 Task.Factory.StartNew 在我的应用程序,但有一件事,我发现改变的是,Visual Studio是没有更多的突破时,未处理的异常发生

I am using async await as well as Task.Factory.StartNew in my application but one thing that i noticed changed is that visual studio is no more breaking when an unhandled exception occured

下面是我的意思是使用前的await

Here is what i mean by before using await

但之后,我把一个方法成工作和使用等待

but after i turn a method into a Task and use await

它仅在Visual Studio中的输出区域捕获...

It is only captured in the output area in visual studio...

BTW:这对我来说是很奇怪的,因为我是新来的.Net4.5请原谅我,如果没能说明什么我特意但需要再次什么我想知道的是

BTW : It is very strange for me as i am new to .Net4.5 please excuse me if failed to illustrate what i need specifically but again what i want to know is


  • 使用时,我怎么可能做出的例外Visual Studio的突破
    异步的await

推荐答案

在调试器说,异常是由用户code未处理,它的意思是,一个例外传播到框架。由于一个异步任务方法放在其返回工作的异常,异常不传播到框架。像这样的一个例外是的未观察

When the debugger says "Exception was unhandled by user code", what it means is that an exception has propagated up to the framework. Since an async Task method places its exceptions on its returned Task, the exception does not propagate to the framework. An exception like this is unobserved.

如果你想在调试器打破时的例外是的抛出的,然后使用调试器 - >例外 - >检查时抛出框CLR例外

If you want the debugger to break when exceptions are thrown, then use Debugger -> Exceptions -> Check the "Thrown" box for CLR Exceptions.

如果你想的观察的例外,那么的 TaskFactory.StartNew 更改为 Task.Run 并调用等待对返回工作。这将传播异常(包括在 AggregateException )通过和最多的框架。

If you want to observe the exception, then change from TaskFactory.StartNew to Task.Run and call Wait on the returned Task. This will propagate the exception (wrapped in an AggregateException) through Main and up to the framework.

这篇关于TPL歇上未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆