静态终结静态

2023-09-02 11:56:08 作者:池暮

什么是正确的方法来执行一些静态finallization?

What is the right way to perform some static finallization?

没有静态的析构函数。该 AppDomain.DomainUnload 事件不会引发在默认域。该 AppDomain.ProcessExit 事件股所有事件处理程序之间三个秒(默认设置)的总时间,所以它不是真正可用。

There is no static destructor. The AppDomain.DomainUnload event is not raised in the default domain. The AppDomain.ProcessExit event shares the total time of the three seconds (default settings) between all event handlers, so it's not really usable.

推荐答案

基本上,你不能。设计围绕它自己的方式尽最大可能。

Basically, you can't. Design your way around it to the fullest extent possible.

不要忘了,一个程序可以的总是的突然终止反正 - 有人拔出电源是明显的例子。所以,你做任何事情必须是尽力而为 - 在这种情况下,我肯定的希望的是 AppDomain.ProcessExit 就足够好

Don't forget that a program can always terminate abruptly anyway - someone pulling out the power being the obvious example. So anything you do has to be "best effort" - in which case I'd certainly hope that AppDomain.ProcessExit would be good enough.

你有什么需要做的,在特定的情况下?

What do you need to do, in your particular case?