2013-05-02 53 views
1

所以这是我在一个模块的函数中的代码。我想关闭该程序,我拨打Application.Exit,但它仍在运行。这是否有充分的理由?vb.net程序不关闭

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 
+0

您确定您的代码实际上是跟随Application.Exit调用的路径吗?当你使用调试器时你是否碰到了Application.Exit行?这将是最明显的问题。 – 2013-05-02 17:41:41

+0

是的,我走过它,它继续运行我的代码 - 几乎200行代码之前,我喜欢 - 并且停止调试 – Pakk 2013-05-02 17:51:46

+0

为什么你从一个模块开始? movePictures()会发生什么? movingPictures中有**循环**吗?您发布的代码如何再次触发? – 2013-05-02 17:55:58

回答

2

processLock是什么?是否有其他线程正在执行?如果是这样,这可能是你的问题。

0

Exit方法不会引发Closed和Closing事件,这些事件在.NET Framework 2.0中已过时。

当调用Application.Exit方法来退出应用程序时,不会引发Form.Closed和Form.Closing事件。如果您在必须执行的任一事件中都有验证代码,则应在调用Exit方法之前分别调用每个打开窗体的Form.Close方法。

根据什么都被调用尝试这样的事情......

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

此外,请确认您的代码在Apllication.Exit()换行。您可能需要使用.close方法明确关闭模式对话框...