.Net 中的 ShowDialog [英] ShowDialog in .Net
本文介绍了.Net 中的 ShowDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道你应该总是在模态表单上调用 dispose .不过,我有一个相关的问题.
I know that you should always call dispose on modal forms. However, I have a related question.
如果我的应用程序中有一个方法,例如
If I have a method in my application like
Private Sub tempMethod
Dim expForm as new ExplorerForm(tempDataTable)
expForm.ShowDialog
'Should I call dispose here?
'or would the form be automatically disposed when it goes out of scope
'after this method exits?
End Sub
推荐答案
当表单超出范围时,它会在未来的某个时刻被垃圾回收,然后会调用 Dispose,但最好使用 Using本例中的关键字:
When the form goes out of scope, it will be garbage collected at some point in the future and Dispose will be called then, but it's better to use the Using keyword in this instance:
Private Sub tempMethod
Using expForm As New ExplorerForm(tempDataTable)
expForm.ShowDialog()
'Other code here
End Using 'Form disposed here
End Sub
这篇关于.Net 中的 ShowDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文