Pakk
Pakk

Reputation: 1339

vb.net Program not closing

So this is my code in a Function of a Module. I'd like to close the program where I call Application.Exit, but it keeps running. Is there a good reason for that?

  Dim OpenFileDialog1 As New FolderBrowserDialog
    If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then

        pictureFolder = OpenFileDialog1.SelectedPath

        movingPictures(pictureFolder)

        'GetImagePath()

    Else

        Dim answer As DialogResult
        answer = MessageBox.Show("The Program needs this folder to continue, " & vbCrLf & _
                                  "Choose Retry to try again, or Cancel to close.", "Retry or Close?", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information)
        If answer = vbRetry Then
            GoTo RepickOpenfileDialog
        Else
            ' essentially ... here is where I'd like to close the program ... 
            ' but it simply won't... it keeps running though the code... 
            ' there a good reason for that ?
            Application.Exit()
            Form1.Close()
        End If
    End If
    processLock = 0

Upvotes: 1

Views: 906

Answers (2)

ѺȐeallү
ѺȐeallү

Reputation: 3017

The Exit method does not raise the Closed and Closing events, which are obsolete as of .NET Framework 2.0.

The Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form.Close method for each open form individually before calling the Exit method.

Depending on what all is invoked try something like this...

If Not answer = vbRetry Then
        Form1.Close()
        Application.Exit()
    Else
        GoTo RepickOpenfileDialog
End If

Additionally, please verify your code is breaking on the Apllication.Exit() line. You may need to explicit close the modal dialog using the .close method...

Upvotes: 0

Seth Moore
Seth Moore

Reputation: 3545

What is processLock? Are there other threads being executed? If so this could be your problem.

Upvotes: 2

Related Questions