调试语句执行计数器

Debug statement execution counter

有没有办法在 C# 中获取 Visual Studio 中的语句执行计数器? 因此,当我在使用调试器深入研究代码后遇到错误时,有很多循环,我想进入导致问题的函数,而我已经通过调试器解决了它。所以我可以把这一行放在有问题的函数之前:

if (Global_execution_counter == 5484984)
 int d = 0; // put debug breakpoint here
execute_problematic_function (); // wanna step into this function

是的,你可以,而且不需要任何全局变量计数器。 解决方案是使用 hit count breakpoint.

execute_problematic_function ();设置断点;右键单击它以显示上下文菜单:

然后单击"Conditions"、select "Hit count"并将其设置为您想要的任何值。

如果您仍然不知道需要将断点设置为多少命中数,you can take advantage of the breakpoints window,它将告诉您断点的当前值: