处理表格。 [英] Disposing of Forms.

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

问题描述

如果我使用ShowDialog方法显示表单,则表单关闭时

我是否必须在表单上显式调用dispose以确保它发布

发布它的资源,或者应该由垃圾收集器处理

当实例化并打开表单的方法超出范围时?


谢谢,


Adam

If I display a form using the ShowDialog method, when the form is closed
should I have to explicitly call dispose on the form in order to ensure it
releases its resources, or should this be handled by the garbage collector
when the method that instantiates and opens the form goes out of scope?

Thanks,

Adam

推荐答案

无论如何,即使你有垃圾也没有错误处理对象

收藏家

" AP" <广告*** @ indra.com>在消息中写道

news:uP ************** @ tk2msftngp13.phx.gbl ...
In any way it isn''t error to dispose an object even you have a garbage
collector
"AP" <ad***@indra.com> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
如果我显示表格使用ShowDialog方法,当表单关闭时我是否必须在表单上显式调用dispose以确保它释放其资源,或者应该由垃圾收集器处理
当实例化并打开表单的方法超出范围时?

感谢,

Adam
If I display a form using the ShowDialog method, when the form is closed
should I have to explicitly call dispose on the form in order to ensure it
releases its resources, or should this be handled by the garbage collector
when the method that instantiates and opens the form goes out of scope?

Thanks,

Adam



AP,


如果您不打算再次使用该对话框(您可能想再次显示它

,因此请保持它周围,你应该调用Dispose。这个

会释放它所持有的任何你不想等待的资源

供GC处理。这可以包括窗口句柄(在这个

的情况下),或其他非托管资源。


希望这会有所帮助。

- -

- Nicholas Paldino [.NET / C#MVP]

- mv * @ spam.guard.caspershouse.com


" AP" <广告*** @ indra.com>在消息中写道

news:uP ************** @ tk2msftngp13.phx.gbl ...
AP,

If you are not going to use the dialog again (you might want to show it
again, and therefore keep it around), you should call Dispose on it. This
will release any resources that it is holding that you don''t want to wait
for the GC to dispose of. This can consist of window handles (in this
case), or other unmanaged resources.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"AP" <ad***@indra.com> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
如果我显示表格使用ShowDialog方法,当表单关闭时我是否必须在表单上显式调用dispose以确保它释放其资源,或者应该由垃圾收集器处理
当实例化并打开表单的方法超出范围时?

感谢,

Adam
If I display a form using the ShowDialog method, when the form is closed
should I have to explicitly call dispose on the form in order to ensure it
releases its resources, or should this be handled by the garbage collector
when the method that instantiates and opens the form goes out of scope?

Thanks,

Adam



你应该在所有模态对话框上调用Dispose。


参见 http://www.milbertus.com/archives/2004/02/003013.php 再多一点

洞察这个以及一些关于

问题的更深入文章的链接......


-

Leit Rachsor
You should call Dispose on all modal dialogs as a matter of course.

See http://www.milbertus.com/archives/2004/02/003013.php for a little more
insight to this as well as some links to more in depth articles on the
issue...

--
Leit Rachsor


这篇关于处理表格。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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