妥善处理扔在一个线程或通过WPF调度异常 [英] Properly handling exceptions thrown in a thread or via the WPF dispatcher

查看:155
本文介绍了妥善处理扔在一个线程或通过WPF调度异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个线程抛出一个异常,也就是未处理,它终止。什么是正确的方式来处理扔在线程以及如何将相关的异常数据传播到的code,将需要订阅通知其他部位的异常?是否有一个INotifyThreadPoorlyDesigned接口,我错过了什么地方?

When a thread throws an exception that is unhandled, it terminates. What is the proper way to handle exceptions thrown on threads and how to propogate relevant exception data to other parts of the code that would need to subscribe to notifications? Is there an INotifyThreadPoorlyDesigned interface that I missed somewhere?

同样适用于如何处理的东西分派到WPF UI。

Same applies for how to handle stuff dispatched to the WPF UI.

推荐答案

要处理的工作,在调度线程抛出一个异常,只需简单勾<一href="http://msdn.microsoft.com/en-us/library/system.windows.application.dispatcherunhandledexception.aspx"相对=nofollow>的应用程序:: DispatcherUnhandledException 事件。为了处理非dispathcer线程异常,你只需要连接标准的AppDomain :: UnhandledException 事件

To handle work that throws an exception on a dispatcher thread, simply hook the Application::DispatcherUnhandledException event. To handle non-dispathcer thread exceptions, you just need to hook the standard AppDomain::UnhandledException event.

这篇关于妥善处理扔在一个线程或通过WPF调度异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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