关于AppDomain 的 UnhandledException事件

2024-02-12 10:18

本文主要是介绍关于AppDomain 的 UnhandledException事件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这个事件实际上只是一个通知处理,并不是一个异常处理,在.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事件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/702388

相关文章

Python中的异步:async 和 await以及操作中的事件循环、回调和异常

《Python中的异步:async和await以及操作中的事件循环、回调和异常》在现代编程中,异步操作在处理I/O密集型任务时,可以显著提高程序的性能和响应速度,Python提供了asyn... 目录引言什么是异步操作?python 中的异步编程基础async 和 await 关键字asyncio 模块理论

禁止平板,iPad长按弹出默认菜单事件

通过监控按下抬起时间差来禁止弹出事件,把以下代码写在要禁止的页面的页面加载事件里面即可     var date;document.addEventListener('touchstart', event => {date = new Date().getTime();});document.addEventListener('touchend', event => {if (new

FreeRTOS内部机制学习03(事件组内部机制)

文章目录 事件组使用的场景事件组的核心以及Set事件API做的事情事件组的特殊之处事件组为什么不关闭中断xEventGroupSetBitsFromISR内部是怎么做的? 事件组使用的场景 学校组织秋游,组长在等待: 张三:我到了 李四:我到了 王五:我到了 组长说:好,大家都到齐了,出发! 秋游回来第二天就要提交一篇心得报告,组长在焦急等待:张三、李四、王五谁先写好就交谁的

【经验交流】修复系统事件查看器启动不能时出现的4201错误

方法1,取得『%SystemRoot%\LogFiles』文件夹和『%SystemRoot%\System32\wbem』文件夹的权限(包括这两个文件夹的所有子文件夹的权限),简单点说,就是使你当前的帐户拥有这两个文件夹以及它们的子文件夹的绝对控制权限。这是最简单的方法,不少老外说,这样一弄,倒是解决了问题。不过对我的系统,没用; 方法2,以不带网络的安全模式启动,运行命令行,输入“ne

BT天堂网站挂马事件后续:“大灰狼”远控木马分析及幕后真凶调查

9月初安全团队披露bt天堂网站挂马事件,该网站被利用IE神洞CVE-2014-6332挂马,如果用户没有打补丁或开启安全软件防护,电脑会自动下载执行大灰狼远控木马程序。 鉴于bt天堂电影下载网站访问量巨大,此次挂马事件受害者甚众,安全团队专门针对该木马进行严密监控,并对其幕后真凶进行了深入调查。 一、“大灰狼”的伪装 以下是10月30日一天内大灰狼远控的木马样本截图,可以看到该木马变种数量不

react笔记 8-19 事件对象、获取dom元素、双向绑定

1、事件对象event 通过事件的event对象获取它的dom元素 run=(event)=>{event.target.style="background:yellowgreen" //event的父级为他本身event.target.getAttribute("aid") //这样便获取到了它的自定义属性aid}render() {return (<div><h2>{

react笔记 8-18 事件 方法 定义方法 获取/改变数据 传值

1、定义方法并绑定 class News extends React.Component {constructor(props) {super(props)this.state = {msg:'home组件'}}run(){alert("我是一个run") //方法写在类中}render() {return (<div><h2>{this.state.msg}</h2><button onCli

【Qt】定时器事件

定时器事件 在之前学习QTimer中实现了定时器的功能,而在QTimer背后是QTimerEvent定时器事件进行支撑的。在QObject中提供了一个timeEvent这个函数。 startTimer启动定时器killTimer关闭定时器 Qt 中在进⾏窗⼝程序的处理过程中,经常要周期性的执⾏某些操作,或者制作⼀些动画效果,使⽤定 时器就可以实现。所谓定时器就是在间隔⼀定时间后,去执⾏某⼀

Imageview在百度地图中实现点击事件

1.首先第一步,需要声明的全局有关类的引用 private BMapManager mBMapMan; private MapView mMapView; private MapController mMapController; private RadioGroup radiogroup; private RadioButton normalview; private RadioBu

Winform中在窗体中的Paint事件中重绘会导致递归问题?

在 WinForms 应用程序中,如果在窗体的 Paint 事件处理程序中不断调用 Invalidate 方法,确实可能会导致递归调用的问题。这是因为每次调用 Invalidate 方法时,都会向消息队列添加一个绘制消息,当消息队列中的绘制消息被处理时,会触发 Paint 事件。如果 Paint 事件处理程序中又调用了 Invalidate,就会形成一个循环,导致递归调用 Paint 事件,这