Closing my application

John Cassell

Well-known member
Joined
Mar 20, 2007
Messages
65
Programming Experience
Beginner
Hi There, can someone tell me what I am doing wrong here pls..

In 'My Project' settings, the shutdown mode is set to 'When last form closes'.

I have this code below to ask if you really want to quit. If I don't include the line 'application.exit' then the form disappears but the program is still running (in debug mode) but if I do include it, then it msgbox appears again after you have clicked Yes the first time.

VB.NET:
Private Sub MainFrm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            Dim res = MessageBox.Show("Are you sure you want to close this window?", _
                           "Your application", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            If res = vbYes Then
                Log_In.TBL_UsersTableAdapter.LogOutUser(String.Empty, Current_UserLbl.Text)
                Application.Exit()
            Else
                e.Cancel = True
            End If
        Catch ee As Exception
            Throw ee
        End Try
    End Sub

Can anyone spot what I am doing wrong?
Thanks

John
 
You don't include "Application.Exit()", when that event happens the form is about to close and will do unless you cancel it. If it is the last form open application will exit. If your application don't stop when last form close you must have another foreground thread running somewhere.
 
Yes John, I didn't think I had something else open but now that you have mentioned it I realized that my original Log In form had been hidden as opposed to Closed.

Thanks for that and for all your help so far today on other things..
 
Back
Top