Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net Visual Studio调试器正在跳过/退出循环_Vb.net_Debugging_Visual Studio 2012 - Fatal编程技术网

Vb.net Visual Studio调试器正在跳过/退出循环

Vb.net Visual Studio调试器正在跳过/退出循环,vb.net,debugging,visual-studio-2012,Vb.net,Debugging,Visual Studio 2012,我有以下代码来清理服务器上的一组目录。我试图一步一步地检查代码以验证它是否有效,但调试器中出现了一个奇怪的行为。我在第一行上放置一个断点,然后按F8单步执行。当它到达for循环时,它会命中第一个if语句一次,然后跳出循环。for循环正在迭代的集合中有4个项,我希望能够逐步遍历该循环并观察它对集合中的每个项所做的操作,但事实并非如此。有什么想法吗 下面是有问题的代码块: Dim Dirs As New Collection(Of DirectoryInfo) Dirs.Add(New Direct

我有以下代码来清理服务器上的一组目录。我试图一步一步地检查代码以验证它是否有效,但调试器中出现了一个奇怪的行为。我在第一行上放置一个断点,然后按F8单步执行。当它到达for循环时,它会命中第一个if语句一次,然后跳出循环。for循环正在迭代的集合中有4个项,我希望能够逐步遍历该循环并观察它对集合中的每个项所做的操作,但事实并非如此。有什么想法吗

下面是有问题的代码块:

Dim Dirs As New Collection(Of DirectoryInfo)
Dirs.Add(New DirectoryInfo(HttpContext.Current.Server.MapPath("../PDFS/Reports/")))
Dirs.Add(New DirectoryInfo(HttpContext.Current.Server.MapPath("../PDFS/Statements/")))
Dirs.Add(New DirectoryInfo(HttpContext.Current.Server.MapPath("../PDFS/HistoryStatements/")))
Dirs.Add(New DirectoryInfo(HttpContext.Current.Server.MapPath("../PDFS/ReminderStatements/")))

    For Each di As DirectoryInfo In Dirs
        If di.Exists Then

            CleanDir(di, 60)

            'Remove all previews
            If Directory.Exists(di.FullName & "Preview") Then
                Dim dPreview As New DirectoryInfo(di.FullName & "Preview")
                CleanDir(dPreview, 1)
            End If

        End If
    Next

我最终发现没有一个di.Exists检查返回true,它们都是无效目录。一旦我将目录信息更改为指向实际目录,那么调试器就会正确地遍历代码。我不完全清楚它为什么会这样工作,我希望它能够逐步完成并能够看到它评估每个项目。

在其中抛出一个Try/Catch来检查错误。查看输出窗口中的首次异常通知。不要将此类代码放入Load事件中。我最终发现没有一个di.Exists检查会返回true,它们都是无效目录。一旦我将目录信息更改为指向实际目录,那么调试器就会正确地遍历代码。我不完全确定它为什么会这样工作,我希望它能够逐步通过,并能够看到它评估每个项目。