vb.net问题

Me.Dispose和Me.Close和End有什么区别?哪个资源释放的更彻底?... Me.Dispose和Me.Close和End有什么区别?哪个资源释放的更彻底? 展开
 我来答
恋圈圈儿
2015-10-31 · TA获得超过3.7万个赞
知道大有可为答主
回答量:6318
采纳率:91%
帮助的人:619万
展开全部
  me.dispose是最彻底释放资源; Me.Close 是关闭 end 只是结束 一般用在程序的语句中,如结束语句。
  执行 dispose 后,由.net 的GC垃圾回收器周期性地回收资源, me.close 方法的基类会调用 dispose 方法end 是从vb中继承下来的语句,直接指示退出程序.程序的资源将被释放,程序并未希望结束时,不适合使用该方法.若要强行退出应用程序,
匿名用户
2013-05-07
展开全部
执行 dispose 后,由.net 的GC垃圾回收器周期性地回收资源, me.close 方法的基类会调用 dispose 方法end 是从vb中继承下来的语句,直接指示退出程序.程序的资源将被释放,程序并未希望结束时,不适合使用该方法.若要强行退出应用程序,在.net中可以使用Environment.Exit(0) 下面是 system.windows.forms.form 类对 close 和 dispose 的封装:'------- ClosePublic Sub Close()
If MyBase.GetState(&H40000) Then
Throw New InvalidOperationException(SR.GetString("ClosingWhileCreatingHandle", New Object() { "Close" }))
End If
If MyBase.IsHandleCreated Then
Me.closeReason = CloseReason.UserClosing
MyBase.SendMessage(&H10, 0, 0)
Else
MyBase.Dispose
End If
End Sub '------- Dispose Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
Me.CalledOnLoad = False
Me.CalledMakeVisible = False
Me.CalledCreateControl = False
If MyBase.Properties.ContainsObject(Form.PropAcceptButton) Then
MyBase.Properties.SetObject(Form.PropAcceptButton, Nothing)
End If
If MyBase.Properties.ContainsObject(Form.PropCancelButton) Then
MyBase.Properties.SetObject(Form.PropCancelButton, Nothing)
End If
If MyBase.Properties.ContainsObject(Form.PropDefaultButton) Then
MyBase.Properties.SetObject(Form.PropDefaultButton, Nothing)
End If
If MyBase.Properties.ContainsObject(Form.PropActiveMdiChild) Then
MyBase.Properties.SetObject(Form.PropActiveMdiChild, Nothing)
End If
If (Not Me.MdiWindowListStrip Is Nothing) Then
Me.MdiWindowListStrip.Dispose
Me.MdiWindowListStrip = Nothing
End If
If (Not Me.MdiControlStrip Is Nothing) Then
Me.MdiControlStrip.Dispose
Me.MdiControlStrip = Nothing
End If
If (Not Me.MainMenuStrip Is Nothing) Then
Me.MainMenuStrip = Nothing
End If
Dim form As Form = DirectCast(MyBase.Properties.GetObject(Form.PropOwner), Form)
If (Not form Is Nothing) Then
form.RemoveOwnedForm(Me)
MyBase.Properties.SetObject(Form.PropOwner, Nothing)
End If
Dim formArray As Form() = DirectCast(MyBase.Properties.GetObject(Form.PropOwnedForms), Form())
Dim i As Integer = (MyBase.Properties.GetInteger(Form.PropOwnedFormsCount) - 1)
Do While (i >= 0)
If (Not formArray(i) Is Nothing) Then
formArray(i).Dispose
End If
i -= 1
Loop
If (Not Me.smallIcon Is Nothing) Then
Me.smallIcon.Dispose
Me.smallIcon = Nothing
End If
Me.ResetSecurityTip(False)
MyBase.Dispose(disposing)
Me.ctlClient = Nothing
Dim menu As MainMenu = Me.Menu
If ((Not menu Is Nothing) AndAlso (menu.ownerForm Is Me)) Then
menu.Dispose
MyBase.Properties.SetObject(Form.PropMainMenu, Nothing)
End If
If (Not MyBase.Properties.GetObject(Form.PropCurMenu) Is Nothing) Then
MyBase.Properties.SetObject(Form.PropCurMenu, Nothing)
End If
Me.MenuChanged(0, Nothing)
Dim menu2 As MainMenu = DirectCast(MyBase.Properties.GetObject(Form.PropDummyMenu), MainMenu)
If (Not menu2 Is Nothing) Then
menu2.Dispose
MyBase.Properties.SetObject(Form.PropDummyMenu, Nothing)
End If
Dim menu3 As MainMenu = DirectCast(MyBase.Properties.GetObject(Form.PropMergedMenu), MainMenu)
If (Not menu3 Is Nothing) Then
If ((menu3.ownerForm Is Me) OrElse (menu3.form Is Nothing)) Then
menu3.Dispose
End If
MyBase.Properties.SetObject(Form.PropMergedMenu, Nothing)
End If
Else
MyBase.Dispose(disposing)
End If
End Sub
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-05-07
展开全部
执行 dispose 后,由.net 的GC垃圾回收器周期性地回收资源, me.close 方法的基类会调用 dispose 方法end 是从vb中继承下来的语句,直接指示退出程序.程序的资源将被释放,程序并未希望结束时,不适合使用该方法.若要强行退出应用程序,在.net中可以使用Environment.Exit(0) 下面是 system.windows.forms.form 类对 close 和 dispose 的封装:'------- ClosePublic Sub Close()
If MyBase.GetState(&H40000) Then
Throw New InvalidOperationException(SR.GetString("ClosingWhileCreatingHandle", New Object() { "Close" }))
End If
If MyBase.IsHandleCreated Then
Me.closeReason = CloseReason.UserClosing
MyBase.SendMessage(&H10, 0, 0)
Else
MyBase.Dispose
End If
End Sub '------- Dispose Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
Me.CalledOnLoad = False
Me.CalledMakeVisible = False
Me.CalledCreateControl = False
If MyBase.Properties.ContainsObject(Form.PropAcceptButton) Then
MyBase.Properties.SetObject(Form.PropAcceptButton, Nothing)
End If
If MyBase.Properties.ContainsObject(Form.PropCancelButton) Then
MyBase.Properties.SetObject(Form.PropCancelButton, Nothing)
End If
If MyBase.Properties.ContainsObject(Form.PropDefaultButton) Then
MyBase.Properties.SetObject(Form.PropDefaultButton, Nothing)
End If
If MyBase.Properties.ContainsObject(Form.PropActiveMdiChild) Then
MyBase.Properties.SetObject(Form.PropActiveMdiChild, Nothing)
End If
If (Not Me.MdiWindowListStrip Is Nothing) Then
Me.MdiWindowListStrip.Dispose
Me.MdiWindowListStrip = Nothing
End If
If (Not Me.MdiControlStrip Is Nothing) Then
Me.MdiControlStrip.Dispose
Me.MdiControlStrip = Nothing
End If
If (Not Me.MainMenuStrip Is Nothing) Then
Me.MainMenuStrip = Nothing
End If
Dim form As Form = DirectCast(MyBase.Properties.GetObject(Form.PropOwner), Form)
If (Not form Is Nothing) Then
form.RemoveOwnedForm(Me)
MyBase.Properties.SetObject(Form.PropOwner, Nothing)
End If
Dim formArray As Form() = DirectCast(MyBase.Properties.GetObject(Form.PropOwnedForms), Form())
Dim i As Integer = (MyBase.Properties.GetInteger(Form.PropOwnedFormsCount) - 1)
Do While (i >= 0)
If (Not formArray(i) Is Nothing) Then
formArray(i).Dispose
End If
i -= 1
Loop
If (Not Me.smallIcon Is Nothing) Then
Me.smallIcon.Dispose
Me.smallIcon = Nothing
End If
Me.ResetSecurityTip(False)
MyBase.Dispose(disposing)
Me.ctlClient = Nothing
Dim menu As MainMenu = Me.Menu
If ((Not menu Is Nothing) AndAlso (menu.ownerForm Is Me)) Then
menu.Dispose
MyBase.Properties.SetObject(Form.PropMainMenu, Nothing)
End If
If (Not MyBase.Properties.GetObject(Form.PropCurMenu) Is Nothing) Then
MyBase.Properties.SetObject(Form.PropCurMenu, Nothing)
End If
Me.MenuChanged(0, Nothing)
Dim menu2 As MainMenu = DirectCast(MyBase.Properties.GetObject(Form.PropDummyMenu), MainMenu)
If (Not menu2 Is Nothing) Then
menu2.Dispose
MyBase.Properties.SetObject(Form.PropDummyMenu, Nothing)
End If
Dim menu3 As MainMenu = DirectCast(MyBase.Properties.GetObject(Form.PropMergedMenu), MainMenu)
If (Not menu3 Is Nothing) Then
If ((menu3.ownerForm Is Me) OrElse (menu3.form Is Nothing)) Then
menu3.Dispose
End If
MyBase.Properties.SetObject(Form.PropMergedMenu, Nothing)
End If
Else
MyBase.Dispose(disposing)
End If
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-05-07
展开全部
me.dispose这个是最彻底 释放资源 Me.Close 这个是关闭 end 只是结束 一般用在程序的语句中 如结束语句
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式