积极答复者
如何在WinForm中捕获一般Task异常?

问题
-
我们知道,Task本质运行在一个线程池(ThreadPool)上,因此无法直接捕获其异常。
现在问题在于:如何在WinForm中捕获这个异常?
注意:我现在只想用TaskScheduler.UnobservedTaskException,其它方法暂不考虑(比如Continue,Wait等方法)。
另外烦请告知TaskScheduler为什么可以捕获全局对象的Task的异常?
ASP.NET Forum
StackOverFlow
FreeRice Donate
Issues to report
Free Tech Books Search and Download
答案
-
你好 ThankfulHeart,
>>现在问题在于:如何在WinForm中捕获这个异常?
你可以参考一下下面这个帖子,上面提到了TaskScheduler.UnobservedTaskException 在 winform apps 中的用法。
>>另外烦请告知TaskScheduler为什么可以捕获全局对象的Task的异常?
参考下面的链接, 如果Task 没有处理异常, 一旦task被回收, finalizer thread 会抛UnobservedTaskException异常。
http://tpodolak.com/blog/2015/08/10/tpl-exception-handling-and-unobservedtaskexception-issue/
Best regards,
Cole Wu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 ThankfulHeartModerator 2016年9月14日 11:39
全部回复
-
你好 ThankfulHeart,
>>现在问题在于:如何在WinForm中捕获这个异常?
你可以参考一下下面这个帖子,上面提到了TaskScheduler.UnobservedTaskException 在 winform apps 中的用法。
>>另外烦请告知TaskScheduler为什么可以捕获全局对象的Task的异常?
参考下面的链接, 如果Task 没有处理异常, 一旦task被回收, finalizer thread 会抛UnobservedTaskException异常。
http://tpodolak.com/blog/2015/08/10/tpl-exception-handling-and-unobservedtaskexception-issue/
Best regards,
Cole Wu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 ThankfulHeartModerator 2016年9月14日 11:39
-
是的,谢谢各位。
最好加上一句:
GC.WaitForPendingFinalizers();
ASP.NET Forum
StackOverFlow
FreeRice Donate
Issues to report
Free Tech Books Search and Download