默认 AppDomain 的卸载事件? [英] Unload event for the default AppDomain?

查看:30
本文介绍了默认 AppDomain 的卸载事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 any AppDomain 卸载时触发一个事件 - 包括进程中的默认事件.AppDomain.DomainUnload 的问题在于它只为非默认 AppDomains 触发.此外,AppDomain.ProcessExit 的执行时间有限,我无法依赖.

I need to have an event fired whenever any AppDomain unloads - including the default one of the process. The problem with AppDomain.DomainUnload is that it only fires for non-default AppDomains. Furthermore, AppDomain.ProcessExit has limited execution time, which I cannot rely on.

任何有关我如何实现这一目标的建议将不胜感激!

Any suggestions as to how I can achieve this would be greatly appreciated!

(或者,在后台线程 (Thread.IsBackground == True) 也工作时触发事件.)

(Alternatively, having an event fired when a background thread (Thread.IsBackground == True) works too.)

推荐答案

为什么不把你的代码放在 Main 的末尾?

Why do you not put your code in the end of Main?

至于事件:

不,在卸载应用程序域时不会执行任何事件.如果您是库开发人员,您可以在入口类中添加析构函数.但请注意,可能无法正确收集所有内容.阅读此答案:https://stackoverflow.com/a/2735431/70386

No there is no event which will get executed when the application domain is unloaded. If you are a library developer you add a destructor to your entry class. But beware that everything might not be collected properly. Read this answer: https://stackoverflow.com/a/2735431/70386

这篇关于默认 AppDomain 的卸载事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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