静态析构函数 [英] static destructor

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

问题描述

C#有静态构造函数里面做一些初始化。 (可能做一些非托管资源初始化)我想知道是否有静电destuctor?

c# has static constructor which do some initialization. (Likely Do some unmanaged resource initialization) I am wondering if there is static destuctor?

推荐答案

没有,没有。

一个静态的析构函数理应会在执行过程的结束时运行。当一个进程死亡,与之相关联的所有内存/句柄将得到释放由操作系统。

A static destructor supposedly would run at the end of execution of a process. When a process dies, all memory/handles associated with it will get released by the operating system.

如果你的程序应该做的,在执行结束特定动作(如事务处理数据库引擎,刷新其高速缓存),这将是更为困难,正确处理不仅仅是一张code运行时该过程的正常执行的结束。你必须手动处理事故和意外终止的过程中,并尝试在下次运行恢复反正。 静态析构函数的概念不会帮助那么多。

If your program should do a specific action at the end of execution (like a transactional database engine, flushing its cache), it's going to be far more difficult to correctly handle than just a piece of code that runs at the end of normal execution of the process. You have to manually handle crashes and unexpected termination of the process and try recovering at next run anyway. The "static destructor" concept wouldn't help that much.

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

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