关于AppDomain 的 UnhandledException事件
来源:互联网 发布:绿盟数据库审计型号 编辑:程序博客网 时间:2024/06/05 02:10
这个事件实际上只是一个通知处理,并不是一个异常处理,在.net 2.0中,任何AppDomain的未处理异常都会导致进程的退出,你注册了这个事件只会在退出之前给你个通知,然后你就可以做一些日志或者记录。
你只能在托管线程上监听到AppDomain的这个事件。另外,这个事件必须在Default AppDomain中注册。
关于哪些未处理的异常会终止整个进程,哪些会被消化掉,CLR有一些默认的设置。一般来讲,线程池的线程以及终止线程(Finalizer)以及类似的“可重用”线程会被消化掉。CLR仅仅终止当前的工作单元,进行下一个。主线程上的托管执行代码抛出的未处理异常会终止整个进程。
这篇文章有一些详细的解释,并且描述了如何改变CLR的默认设置。
Managed Application Shutdown
另外,关于在.net 3.5下plugin的异常处理,请看如下描述:
The short answer is that up through .NetFX 3.5 there is no easy way to catch exceptions that go unhandled in child threads. If you use the unmanaged hosting API's to start up and manage the runtime you can use something called "escalation policy" to manage this but there are significant drawbacks to that approach (not the least of which is the amount of effort required).
The best you can generally do is detect which add-in (really which AppDomain) threw the unhandled exception and can do something interesting with that information (such as inform the user or disable the add-in). This is generally enough and is actually the strategy that office uses for its add-ins.
If you're interested in this approach these two blog posts will show you how to do this in the context of our new NetFX 3.5 based add-in model but the techniques they describe are still valid on 2.0 and I believe 1.1:
http://blogs.msdn.com/clraddins/archive/2007/05/01/using-appdomain-isolation-to-detect-add-in-failures-jesse-kaplan.aspx
http://blogs.msdn.com/clraddins/archive/2007/05/03/more-on-logging-unhandledexeptions-from-managed-add-ins-jesse-kaplan.aspx
In general, if you are building your own extensible application with a plug-in/add-in model I encourage you to take a look at the blog. There is a lot of information there about using this new system as well as some good info for those who decide for some reason that they still need to build their own.
原始链接:http://forums.microsoft.com/MSDN/showpost.aspx?postid=1969048&siteid=1
- 关于AppDomain 的 UnhandledException事件
- 关于Thread(lambda,全局捕获异常AppDomain.CurrentDomain.UnhandledException)
- WinForm 处理未处理的异常 Application.ThreadException + AppDomain.CurrentDomain.UnhandledException
- Application.ThreadException 以及 AppDomain.UnhandledException真强!
- 关于AppDomain
- 关于appdomain, assembly, 进程,线程的概念体会
- 关于C#中动态加载AppDomain的问题
- 关于C#中动态加载AppDomain的问题
- 关于appdomain, assembly, 进程,线程的概念体会
- AppDomain
- AppDomain
- AppDomain
- AppDomain
- AppDomain
- AppDomain
- Net下的AppDomain编程
- .Net下的AppDomain编程
- 转的一篇 关于.net appDomain的东西 ,最后写的它的应用场合总结的不错...
- CSS优先级问题
- 自绘编辑框
- .net程序员的盲点
- c#事务的使用、示例及注意事项
- AXIS2测试
- 关于AppDomain 的 UnhandledException事件
- HTML语言剖析(一)
- HTML语言剖析(二)
- Windows局域网共享全攻略
- 指定的参数已超出有效值的范围。参数名: value
- HTML语言剖析(三)
- 如何创建和使用Web Service代理类
- HTML语言剖析(四)
- 我的"Java开发通讯簿系统"开发经历 (六)