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 visual studio called Breakpoint condition came to recue to exactly specify a condition on when the break point needs to be hit. If the specified condition evaluates to true the breakpoint will be hit and allows you have debug further.
Steps to add a condition breakpoint
- 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.
- 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.
- When the breakpoint condition is met the break point will be hit. Later you can debug as usual.