静态终结器 [英] Static Finalizer

查看:28
本文介绍了静态终结器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行某些静态终结的正确方法是什么?

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?

这篇关于静态终结器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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