如何在 vb.net 中正确关闭 Windows 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19744345/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:42:14  来源:igfitidea点击:

How to properly close a windows application in vb.net

vb.net

提问by Jose M.

I have a windows application that when I close it still runs on the background process of task manager. I tried going through Application/Shutdown Mode/When start up form closes, but my startup form is a login form which then takes me to my main application which has a close button. I also tried the option When last form closes, no effect.

我有一个 Windows 应用程序,当我关闭它时,它仍然在任务管理器的后台进程上运行。我尝试通过应用程序/关闭模式/启动表单关闭时,但我的启动表单是一个登录表单,然后将我带到我的主应用程序,它有一个关闭按钮。我也试过这个选项When last form closes,没有效果。

On this close button I have tried Me.Close().and also I have tried Application.Quit()my both still not closing my application completely.

在这个关闭按钮上,我已经尝试过Me.Close().,并且我也尝试过Application.Quit()我的两个按钮仍然没有完全关闭我的应用程序。

How can I terminate the application completely and clear it from the background services?

如何完全终止应用程序并将其从后台服务中清除?

采纳答案by 06needhamt

use Application.Exitor End...

使用Application.ExitEnd...

回答by Idle_Mind

"my startup form is a login form which then takes me to my main application"

“我的启动表单是一个登录表单,然后将我带到我的主应用程序”

You are probably hiding the login form with Hide(), which is keeping the app alive. With the When last form closesoption set, you can instead call Close() against the login form after showing the main form. Then it should shut down properly.

您可能使用 Hide() 隐藏了登录表单,这使应用程序保持活动状态。通过When last form closes选项进行设置,可以改为调用Close()方法对登录表单显示的主要形式后。然后它应该正确关闭。

回答by Devendra Dora

In Login form

在登录表单中

  1. create a instance of MainForm

  2. show the MainFormand close the Loginform

  3. If you want to pass any value to MainFormfrom Loginform, create a public variable in MainForm. Eg. Public userAuth As String

  1. 创建一个实例 MainForm

  2. 显示MainForm并关闭Login表单

  3. 如果要将任何值传递给MainFormfromLogin表单,请在MainForm. 例如。 Public userAuth As String

Example:

例子:

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim mf As New MainForm()
        mf.userAuth = "Admin"
        mf.Show()
        Me.Close() 
End Sub