停止调试时释放资源 [英] Release resources when stop debugging

查看:162
本文介绍了停止调试时释放资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2005& C#。在我的FormClosing事件中,我发布了我的应用程序使用的一些资源。但是当我调试它并决定停止(停止调试)时,比FormClosing事件不会触发,我的资源没有被正确地释放。

I use Visual Studio 2005 & C#. In my FormClosing event I release some resources, that my application uses. But when I debug it and decide to stop (Stop debugging), than FormClosing event doesn't fire and my resources aren't properly released.

我如何避免这个?

推荐答案

如果你通过资源意味着开放句柄和分配的内存,你不用担心。操作系统将随着进程终止而释放此操作。

If you by "resources" mean things like open handles and allocated memory, you shouldn't worry. The OS will release this as the process terminates.

如果您的意思是临时文件,注册表项或其他提交到磁盘的事情,您想在自己之后清理,我恐怕你赢了在终止程序时,可以抓住它,并且必须手动或下次启动时清理它。据我所知,至少。 :)

If you mean things like temporary files, registry keys, or other things that are committed to disk that you want to clean up after yourself, I'm afraid you won't be able to catch that when terminating the program, and will have to clean it up manually or on next start. To my knowledge, at least. :)

这篇关于停止调试时释放资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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