Hit count breakpoints in Visual Studio

Previously in our discussion, we discussed about the concept of Conditional breakpoints. In this article, we will discuss about the Hit Condition breakpoints.

Consider a case where you have a for loop with iteration of thousands of records. You know that your records at around 500th location is corrupted and you need to debug that value. Will you sit and keep pressing F5 until the record number 500 is reached ? This is where you can use the concept of Hit Condition breakpoints. This is achieved by setting Hit Count condition on the breakpoint i.e. hit the breakpoint when it has iterated 499 times.

Let’s create  a sample application to understand this. Add a for loop with iteration of 1000 records and add a condition to hit the breakpoint when the 500th record is being iterated.

To add the condition, right click on the breakpoint and select the ‘Hit Count’ condition. This will open up a window where we can define a condition to hit the breakpoint only when it meets the criteria set for its execution.

Conditional breakpoints

Here we have 4 different conditions and these. So we select the condition ‘break when the hit count is equal to‘ and set its value to be 500.

Conditional breakpoints

Hover over the breakpoint and see the details:

Conditional breakpoints


Run the application and see the value of variable ‘i’, when the breakpoint is hit.

Conditional breakpoints

So here when the value of i becomes 499 (starting from 0), it is iterating the 500th record and the breakpoint gets hit. So set the break point and enjoy the debugging…!!!


About Jasminder

.Net developer and blogger by profession, keen to learn new technologies, love nature, music and cricket.
This entry was posted in Tips & Tricks. Bookmark the permalink.

I have a suggestion..

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s