Jose M.
Jose M.

Reputation: 2330

How to properly close a windows application in vb.net

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.

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

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

Upvotes: 0

Views: 14494

Answers (3)

Devendra Dora
Devendra Dora

Reputation: 587

In Login form

  1. create a instance of MainForm

  2. show the MainForm and close the Login form

  3. If you want to pass any value to MainForm from Login form, create a public variable in MainForm. Eg. 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

Upvotes: 0

Idle_Mind
Idle_Mind

Reputation: 39122

"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 closes option set, you can instead call Close() against the login form after showing the main form. Then it should shut down properly.

Upvotes: 1

06needhamt
06needhamt

Reputation: 1605

use Application.Exit or End...

Upvotes: 0

Related Questions