关闭与处置 [英] Close vs. Dispose

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

问题描述

我知道以前曾经问过这个问题,但是我遇到了这样的情况:我需要知道关闭和处置之间的区别,我不能得到

我需要从msdn帮助或以前的帖子获得的信息。


我有一个带有计时器的游戏表单,只要游戏正在运行,它就会运行>
玩了。当计时器到达零时,将调用GameOver表单。在

游戏表单上是一个退出按钮,在其点击事件中我只有命令

" Me.Close"。但是,当我在计时器用完之前点击退出时,表格

关闭,但计时器仍然运行。我知道这是因为当我在应用程序中使用

其他表格时,GameOver表格将弹出

无处可去。如果我使用Me.Dispose在退出按钮的点击事件中,有

没问题。


我想知道的是什么基本上和close之间有什么区别? br />
处置?当msdn库说当表格关闭时,所有

资源在对象中创建的资源被关闭并且表格被处理掉?

I know this has been asked previously, but I''ve run into a situation where I
need to know the difference between close and dispose, and I can''t get the
information I need from msdn help or previous posts.

I have a game form that has a timer, which runs as long as the game is being
played. When the timer reaches zero, the GameOver form is called. On the
game form is a Quit button, in whose click event I have only the command
"Me.Close". However, when I hit Quit before the timer runs out, the form
closes, but the timer still runs. I know this because as I''m working with
other forms in the application, the GameOver form will pop up out of
nowhere. If I use "Me.Dispose" in the Quit button''s click event, there is
no problem.

What I want to know is basically what is the difference between close and
dispose? Is msdn library incorrect when it says "When a form is closed, all
resources created within the object are closed and the form is disposed"?

推荐答案

*" Nathan" < NK ********************* @ softhome.net> scripsit:
* "Nathan" <nk*********************@softhome.net> scripsit:
我知道以前曾经问过这个问题,但是我遇到了一个需要知道关闭和处置之间区别的情况,我无法得到我需要从msdn帮助或以前的帖子中获取的信息。

我有一个带有计时器的游戏表单,只要游戏正在播放就会运行。当计时器到达零时,将调用GameOver表单。在
游戏表单上是一个退出按钮,在其点击事件中我只有命令
Me.Close。但是,当我在计时器用完之前点击退出时,表格
关闭,但计时器仍然运行。我知道这是因为当我在应用程序中使用
其他表单时,GameOver表单将弹出
无处。如果我使用Me.Dispose在Quit按钮的click事件中,没有问题。

我想知道的是close和
dispose之间的区别是什么?如果msdn库说当表格关闭时,对象内创建的所有资源都被关闭,表格被处理掉?
I know this has been asked previously, but I''ve run into a situation where I
need to know the difference between close and dispose, and I can''t get the
information I need from msdn help or previous posts.

I have a game form that has a timer, which runs as long as the game is being
played. When the timer reaches zero, the GameOver form is called. On the
game form is a Quit button, in whose click event I have only the command
"Me.Close". However, when I hit Quit before the timer runs out, the form
closes, but the timer still runs. I know this because as I''m working with
other forms in the application, the GameOver form will pop up out of
nowhere. If I use "Me.Dispose" in the Quit button''s click event, there is
no problem.

What I want to know is basically what is the difference between close and
dispose? Is msdn library incorrect when it says "When a form is closed, all
resources created within the object are closed and the form is disposed"?



如果可能,''关闭''会自动处理表格。在您的情况下,

您应该在调用关闭方法之前禁用计时器。

-

Herfried K. Wagner [ MVP]

< http://www.mvps.org/dotnet>



''Close'' will dispose the form automatically, if possible. In your case,
you should disable the timer before calling its ''Close'' method.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


" Nathan" < NK ********************* @ softhome.net> schrieb
"Nathan" <nk*********************@softhome.net> schrieb
我知道以前曾经问过这个问题,但我遇到了一个情况
我需要知道关闭和处置之间的区别,我可以'从msdn帮助或之前的帖子中获取我需要的信息。

我有一个带有计时器的游戏表单,只要正在玩游戏就会运行。当计时器到达零时,将调用GameOver表单。在游戏表单上是一个退出按钮,其点击事件中我只有命令Me.Close。但是,当我在计时器用完之前点击退出时,表单关闭,但计时器仍然运行。我知道这个因为我正在使用应用程序中的其他表单,所以GameOver表单会突然冒出来。如果我在退出按钮的点击事件中使用Me.Dispose
,则没有问题。

我想知道的是什么基本上是什么区别?是和处置?当msdn库说当一个表格关闭时,该对象内创建的所有资源都被关闭并且
表格被处理掉时,msdn库是不正确的吗?
I know this has been asked previously, but I''ve run into a situation
where I need to know the difference between close and dispose, and I
can''t get the information I need from msdn help or previous posts.

I have a game form that has a timer, which runs as long as the game
is being played. When the timer reaches zero, the GameOver form is
called. On the game form is a Quit button, in whose click event I
have only the command "Me.Close". However, when I hit Quit before
the timer runs out, the form closes, but the timer still runs. I
know this because as I''m working with other forms in the application,
the GameOver form will pop up out of nowhere. If I use "Me.Dispose"
in the Quit button''s click event, there is no problem.

What I want to know is basically what is the difference between close
and dispose? Is msdn library incorrect when it says "When a form is
closed, all resources created within the object are closed and the
form is disposed"?




除了Herfried之外:如果你打电话给Form'的Dispose方法,那就是

kill,例如没有关闭和关闭事件发生。这就是为什么你应该给
调用Close方法。


-

Armin
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/ learn2quote.html



In addition to Herfried: If you call the Form''s Dispose method, it is
"killed", e.g. no closing and closed events occur. That''s why you should
call the Close method.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


嗨Nathan,



没有区别,它们是相辅相成的。

关闭,准备一切以结束美好

处理,结束(杀死)它。


Cor

Hi Nathan,

In addition to Herfried and Armin,

There is no difference, they are complementary.
Close, prepare everything for ending nice
Dispose, end (kill) it.

Cor

我知道以前曾经问过这个问题,但我遇到过$ b $的情况b我需要知道关闭和处置之间的区别,我无法从msdn帮助或以前的帖子中获得我需要的信息。

我有一个游戏表单有一个计时器,只要运行游戏是
正在播放。当计时器到达零时,将调用GameOver表单。在
游戏表单上是一个退出按钮,在其点击事件中我只有命令
Me.Close。但是,当我在计时器用完之前点击退出时,表格
关闭,但计时器仍然运行。我知道这是因为当我在应用程序中使用
其他表单时,GameOver表单将弹出
无处。如果我使用Me.Dispose在Quit按钮的click事件中,没有问题。

我想知道的是close和
dispose之间的区别是什么?当msdn库说当表格关闭时,
关闭对象中创建的所有资源并且表格被处理时,msdn库是不正确的吗?
I know this has been asked previously, but I''ve run into a situation where I need to know the difference between close and dispose, and I can''t get the
information I need from msdn help or previous posts.

I have a game form that has a timer, which runs as long as the game is being played. When the timer reaches zero, the GameOver form is called. On the
game form is a Quit button, in whose click event I have only the command
"Me.Close". However, when I hit Quit before the timer runs out, the form
closes, but the timer still runs. I know this because as I''m working with
other forms in the application, the GameOver form will pop up out of
nowhere. If I use "Me.Dispose" in the Quit button''s click event, there is
no problem.

What I want to know is basically what is the difference between close and
dispose? Is msdn library incorrect when it says "When a form is closed, all resources created within the object are closed and the form is disposed"?



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

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