所以这是我的代码在一个模块的函数。我想关闭我调用Application.Exit
的程序,但是它一直在运行。有什么好的理由吗?
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
什么是processLock?是否有其他线程正在执行?如果是这样,这可能是你的问题。
Exit方法不会引发Closed和Closing事件,这在。net Framework 2.0中已经过时了。
表单。封闭和形式。时不会引发关闭事件。方法用于退出应用程序。如果在这两个事件中有必须执行的验证代码,则应该调用Form。在调用Exit方法之前,为每个打开的窗体分别调用Close方法。
根据调用的所有内容尝试这样做…
If Not answer = vbRetry Then
Form1.Close()
Application.Exit()
Else
GoTo RepickOpenfileDialog
End If
另外,请在application . exit()行验证代码是否中断。您可能需要使用。close方法显式地关闭模态对话框…