How to stop debugger after a specific number of breakpoint hit ?

You can stop the debugger at breakpoint after a specific number of breakpoint hit. Hit Count is used to keep track on how many times the debugger has paused at some particular breakpoint. This is extremely useful when you want to stop the debugger after a certain number within a iterative process; and of course where you have nothing to track using conditional break points.

For an example, you have following code block and break point is placed at line number 21, where it is printing some values in  the console. Now you want to check the value for the 3rd item within the collection before it print.image

For the small collection given in the example, you can iterate through the every items and check the values for the specific item. But is it possible to check when the collection size is big ? Say you have 1000 items in the collection and you want to check the  value of 300th elements . At this point of time “Breakpoint Hit Count” features if Visual Studio becomes very handy and useful. 


By default, it’s set to always.  So, whenever the breakpoints hits, hit count will increase automatically but the debugger will stop every time in the breakpoint.  You can also specific the count of hit over here to stop the debugger. For this example we can selection option 2 and set the values of count to 3 as shown in figure below.



Om click of “OK”, the break point icon will change to a conditional break point icon (additional  + Symbol ) to indicate some additional condition has been added with the breakpoint.


Now, if you try to debug the application, the debugger will only stop for the items when break point hit count is equal to 3.

Note: This is not a new features of visual studio, it has been there from early version of Visual Studio. This may be known to many of you, but  few of you may found it interesting.

Interested to learn something more on debugging and breakpoints ? Read this post

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

One Comment to “How to stop debugger after a specific number of breakpoint hit ?”

Comments are closed.