vb.net 如何正确退出应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4276069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to exit an application properly
提问by ghostdog74
Usually, I will just use Environment.Exit(code)
to exit an application. (Usually through a button click.) But I would like to know is it the proper way to exit, ie, releasing memory etc etc...
通常,我只会Environment.Exit(code)
用来退出应用程序。(通常通过单击按钮。)但我想知道这是退出的正确方法,即释放内存等...
回答by Mario
Just Close()
all active/existing forms and the application should exit.
只是Close()
所有活动/现有表单和应用程序应该退出。
回答by Mew
Application.Exit()does the trick too: any forms you have can still cancel this for instance if you want to present a save changes dialog.
Application.Exit()也可以解决这个问题:例如,如果您想显示保存更改对话框,您拥有的任何表单仍然可以取消此操作。
回答by Al.Acoustic
Application.Exit
End
will work like a charm The "END" immediately terminates further execution while "Application.Exit" closes all forms and calls.
将像魅力一样工作“END”立即终止进一步执行,而“Application.Exit”关闭所有表单和调用。
Best regrads,
最好的regrads,
回答by TToni
In a console application, just return from the main program, in a UI-Application Close() all active Forms.
在控制台应用程序中,只需从主程序返回,在 UI-Application Close() 中所有活动的表单。
Memory from managed objects will be handled by the .NET Framework, you don't need to care about this.
来自托管对象的内存将由 .NET Framework 处理,您无需关心这一点。
If you use classes which implement IDisposable (like database connections, for example), you should call Dispose() on them when you no longer need them (preferred way: a using-Statement).
如果您使用实现 IDisposable 的类(例如数据库连接),您应该在不再需要它们时调用它们的 Dispose()(首选方式:使用-Statement)。
If you use such resources globally (like private members in your form), your form should implement the IDisposable pattern to release these resources on the Close()-call. See this articlefor details.
如果您全局使用此类资源(如表单中的私有成员),则您的表单应实现 IDisposable 模式以在 Close() 调用时释放这些资源。有关详细信息,请参阅此文章。
回答by Ameerah
The following code is used in Visual Basicwhen prompting a user to exit the application:
在Visual Basic 中提示用户退出应用程序时使用以下代码:
Dim D As String
D = MsgBox("Are you sure you want to exit?", vbYesNo+vbQuestion,"Thanking You")
If D = vbYes Then
Unload Me
Else
Exit Sub
End If
End
End Sub
回答by Shane
You can use:
您可以使用:
Me.Close
Application.Exit
End
Process immediately terminated in Task Manager Processors!
回答by Jorge Martins
in this case I start Outlook and then close it
在这种情况下,我启动 Outlook 然后关闭它
Dim ol
Set ol = WScript.CreateObject("Outlook.Application") 'Starts Outlook
ol.quit 'Closes Outlook
回答by myra
me.close()
You should try this. I guess it will work.
你应该试试这个。我想它会起作用。