Unload Program From Windows

laroberts

Freshman
Joined
Jun 29, 2005
Messages
34
I have noticed with my VB.NET program that when I click on the X in the right corner of the window to close the program it is still running as a process in Windows. How do I stop this from taking place? When I push the X I want it to clear out of Windows completely.

I know you can use application.exit to terminate everything but that does not help if somebody hits the X in the right corner.

Thank you
 
Last edited:
If you application isn't exiting it usually means you have not closed down all forms you opened or threads you started.
Are you providing an exit button for the users? If so how are you handling the shutdown there?
 
No I can shutdown the application just fine if I use a button for it. Its when a user pushes the X in the right hand corner. I do not want to shutoff the controls up there so there must be a way to take care of that when they push it.
 
What do you do when they use your Exit button/menu option? Do you destroy any objects that are not being disposed properly the other way?
 
You probably still have some hidden forms running or something like that. If you want to terminate the application when the user clicks the "X", then
you might want to do an Application.exit or something similar on the closing event for that form. You can even give the user a messagebox first or
just do an Application.exit on the form closing event.

Visual Basic:
 Private Sub frmMain_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Dim Dgr As DialogResult

        Dgr = MessageBox.Show("Do You Really Want To Exit?", "Confirm Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If Dgr = DialogResult.Yes Then
            Application.Exit()
        Else
            e.Cancel = True
        End If
    End Sub

-=Simcoder=-
 
Application.Exit will not call any code in a form's Closed or Closing events though - if you have validation / save logic in these events then it will be skipped.
Generally it is better to close down resources when you have finished with them - if you ever get to a point when you have resources allocated that you have forgotten about then your code needs revising.
 
Back
Top