14 May 2015

breakpoint condition in visual studio

Recently I was debugging a multithreaded application to root cause an unhandled exception in one of the for-each iteration on a thread. The for-each statement was being executed thousands of times, so it was too much to time to wait for the failing iteration to occur.

To save my time a cool feature in the visual studio called Breakpoint condition came to rescue to exactly specify a condition on when the breakpoint needs to be hit. If the specified condition evaluates to true the breakpoint will be hit and allows you have debug further.

foreach(Control control in controls){
ProcessControl(control);
}

Steps to add a condition breakpoint

  1. In the above for each code, add a break point on the line which is invoking ProcessControl() method. And right click on the breakpoint to open the below menu.
  2. Click on the “Condition…” menu item. It will open the Break point condition windows. Enter your condition there. For the condition you can use any varibale which you can access in the line of code where you have put the breakpoint.
  3. When the breakpoint condition is met the breakpoint will be hit. Later you can debug as usual.

No comments:

Post a Comment