如何做一些事情过程之前在Windows中被打死 [英] How to do something before process get killed in windows

查看:164
本文介绍了如何做一些事情过程之前在Windows中被打死的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序需要占用一定的资源。
我希望它退出前释放这些资源。这很容易实现的时候excutable正常退出。
但是,如果在Windows中的用户打开任务管理器和杀excutable?我的析构函数不会被打到在这种情况下。

My program need to occupy some resources. I want it to release those resources before exit. It's easy to achieve when the excutable exit normally. However, what if the user open task manager in windows and kill the excutable? My destructors won't get hit in this case.

是否有人知道一个良好的parttern解决呢? (C#)

Does anybody know a good parttern to solve this? (C#)

非常感谢,

推荐答案

您不能处理如果用户强行杀死应用程序的情况。但你不必担心资源。 Windows会自动释放被当它杀了你的过程中获得的资源。

You cannot handle the scenario if user kill the application forcefully. But you don't have to worry about the resources. Windows will automatically free the resources acquired by your process when it is killed.

这篇关于如何做一些事情过程之前在Windows中被打死的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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