Breakpoint Hit Count

Command:  EditorContextMenus.CodeWindow.Breakpoint.BreakpointHitCount
Versions:  2008,2010
Published:  4/28/2010
Code:  vstipDebug0019

 

Download the seriously cool Tip of the Day Extension to get the daily tips delivered to your Start Page!

 

Okay so most people know about this already but I was inspired to do this post because of a recent event I did and not ALL people knew about it.  I was a little surprising.  So here we go:  Did you know you can make it so a Breakpoint will not break every time but only when it is hit a certain number of times?  Just right click on any Breakpoint and go to Hit Count:

image

 

This will give you the Breakpoint Hit Count dialog:

image

 

The default is to "break always" but we can change that to one of these options:

image

 

Let's define what each of these options means:

break when the hit count is equal to - Essentially means an exact value.  So if I put in a 5 in this example it will wait until the Breakpoint has been "hit" 5 times before stopping.  This is useful when you pretty much know the number of times you want to loop before stopping.

image

 

 

break when the hit count is a multiple of - This will break every X number of times it is hit.  So if I put in a 5 it will break every 5th time (5, 10, 15, etc.) it is "hit".  This helps when you aren't sure on what iteration the problem is so want to skip in pre-defined increments through the loop.

image

 

The best part is that the Breakpoints Window tells you the Current hit count while you are debugging:

image

 

 

break when the hit count is greater than or equal to - This option will take any number and stop once the Hit Count has reached that number or higher.  Use this option when you may aren't exactly sure what the loop iteration value will be but want to stop when it reaches an upper bound.

image