Visual Studio 调试器正在步进 Over/Out 循环
Visual Studio Debugger is Stepping Over/Out of Loop
我有以下代码来清理我服务器上的一组目录。我正在尝试逐步执行代码以验证它是否有效,但我在调试器中遇到了一个奇怪的行为。我在第一行放置一个断点,然后按 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 检查中的 none 会返回 true,它们都是无效的目录。一旦我将目录信息更改为指向实际目录,调试器就会正确地逐步执行代码。我不完全确定它为什么以这种方式工作,我希望它能够逐步完成并能够观察它评估每个项目。
我有以下代码来清理我服务器上的一组目录。我正在尝试逐步执行代码以验证它是否有效,但我在调试器中遇到了一个奇怪的行为。我在第一行放置一个断点,然后按 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 检查中的 none 会返回 true,它们都是无效的目录。一旦我将目录信息更改为指向实际目录,调试器就会正确地逐步执行代码。我不完全确定它为什么以这种方式工作,我希望它能够逐步完成并能够观察它评估每个项目。