3

我知道您应该始终在模态表单上调用 dispose 。但是,我有一个相关的问题。

如果我的应用程序中有一个方法,例如

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
4

1 回答 1

3

当表单超出范围时,它将在将来的某个时间被垃圾收集,然后调用 Dispose,但在这种情况下最好使用 Using 关键字:

Private Sub tempMethod
    Using expForm As New ExplorerForm(tempDataTable)
        expForm.ShowDialog()

        'Other code here
    End Using      'Form disposed here
End Sub
于 2012-07-27T14:47:16.983 回答