Visual Studio调试器正在遍历/脱离循环



我有以下代码来清理服务器上的一组目录。我试图逐步检查代码以验证它是否工作,但我在调试器中遇到了一个奇怪的行为。我在第一行上放置了一个断点,然后按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

我最终发现。Exists检查将返回true,它们都是无效目录。一旦我将目录infos更改为指向实际目录,调试器就会正确地执行代码。我不完全确定为什么它会以这种方式工作,我希望它能通过并能够观看它评估每一项。

最新更新