.NET结束VS Form.Close()与Application.Exit清洁的方式来结束自己的应用程序 [英] .NET End vs Form.Close() vs Application.Exit Cleaner way to close one's app

查看:400
本文介绍了.NET结束VS Form.Close()与Application.Exit清洁的方式来结束自己的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,当我使用Form.close()我调试程序时,虽然窗体关闭,应用程序仍在运行。我使用MsgBox函数时,注意到了这个问题。

sometimes, when I use Form.close() when debugging my program, although the form is closed, the application is still running. I noticed this behaviour when using the msgbox function.

我没有线索,也没有定时运行,那么什么是关闭一个.net应用程序的最佳方法是什么?我使用VB.NET。

I have no thread nor timer running, so what is the best way to close a .NET app? I am using VB.NET.

感谢

推荐答案

您所描述的情况是pretty的腥。当你关闭你的程序的启动形式,整个应用程序会自动退出,包括关闭的其他的公开形式。请确保您正在关闭正确的形式,你应该不会遇到任何问题。

The situation you describe is pretty fishy. Whenever you close your program's startup form, the entire application should quit automatically, including closing all other open forms. Make sure that you're closing the correct form, and you should not experience any problems.

另一种可能性是,你已经改变了你的项目(使用它的属性页)不关闭,直到的所有的打开的窗口已经关闭。在这种模式下,你的应用程序不会退出,直到最后的保持开放的形式已经关闭。如果你选择这个设置,你必须确保你调用的关闭方法的您在过程中所显示的所有的形式应用程序,而不仅仅是启动/主要形式。

The other possibility is that you've changed your project (using its Properties page) not to close until all open windows have been closed. In this mode, your application will not exit until the last remaining open form has been closed. If you've chosen this setting, you have to make sure that you call the Close method of all forms that you've shown during the course of application, not just the startup/main form.

第一个设置为默认值是有原因的,如果你已经改变了它,你可能想要去解决它了。
这是迄今为止最直观的模型用于正常的应用程序,它prevents正是你所描述的情况。对于正常的工作,请确保您已指定您的的形式为启动形式(而不是闪屏或登录表格)。

The first setting is the default for a reason, and if you've changed it, you probably want to go fix it back.
It is by far the most intuitive model for normal applications, and it prevents exactly the situation you describe. For it to work properly, make sure that you have specified your main form as the "Startup form" (rather than a splash screen or log-in form).

我说的是这里突出显示的设置:

The settings I'm talking about are highlighted here:

   

   

不过为主,需要注意的是你不应该叫 Application.Exit 在一个适当设计的应用程序。如果你发现自己不得不这样做是为了让你的程序完全关闭,那么你正在做的事情是错误的。否则它本身并不是一个不好的做法,只要你有一个很好的理由。另外两个答案无法解释这一点,所以我觉得是不完整的,在最好的。

But primarily, note that you should never have to call Application.Exit in a properly-designed application. If you find yourself having to do this in order for your program to close completely, then you are doing something wrong. Doing it is not a bad practice in itself, as long as you have a good reason. The other two answers fail to explain that, and thus I feel are incomplete at best.

这篇关于.NET结束VS Form.Close()与Application.Exit清洁的方式来结束自己的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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