Visual studio and .NET tip 9:- Conditional Breakpoints

By Shivprasad Koirala

As developer debugging is your routine job and you would like your debugger to debug smartly rather than monotonously. For instance in the below code we have put a debug point and we do not want our debugger to just break monotonously.

Visual studio and .NET tip 9:- Conditional Breakpoints

As developer debugging is your routine job and you would like your debugger to debug smartly rather than monotonously. For instance in the below code we have put a debug point and we do not want our debugger to just break monotonously.

For instance you would like your debugger to break when the variable “str” value is set to “shiv”  and not for any other condition , welcome to conditional debugging feature.



So first set a break point and right click on the break point and click condition menu as shown in the below figure.



You will be then popped up with a simple expression window where in you can write when you want your debugger to start debugging. For instance in the below figure we have stated when the “str” value is set to “shiv” then only break in debugging mode or else just continue in a normal manner.




Now if you run your debugger, the debugger will only start debugging when your “str” value is set to “shiv” via console input.

Many times you want to break depending on the number of times the debugging point was hit. For those situations you can use “Breakpoint hit count” as shown in the below figure. For example you want to break when the debugger hits the debug point at least 4 times.



So select the second option “Break when the hit count is equal to” and a dialog box as shown in the below figure is popped up.  You can then enter hit count and the debugger will break accordingly as per number of debug hits.



You can see the video for above trick:- http://youtu.be/MCQ63H4zciw?hd=1

Related FAQs

When we select source code in visual studio it selects the complete source code , but what if we want to select the code in a rectangular manner?
In this section we will see a very interesting and useful trick of visual studio called the extract method.
Now many times as a .NET developer we need connection strings to connect to databases. Connection string are long and cryptic and very difficult to remember. In this tip we will see a easy way of getting connection strings.
Many times we write comments in code to remind about certain tasks to be performed later and then we forget about the same as the comments gets lost in those million lines code.
Many times due to project pressure and lazy attitude you violate encapsulation and create public variables for classes as shown below. Even though your inner heart knows that the best practice is to create set and get property function but your lazy attitude overrules it.
While debugging you often want to skip debugging on certain lines of code. For instance in the below code you have set the debug point to the first line, you would like to skip the in between lines and jump directly to “console.writeline” step.
Visual studio and .NET tip 9:- Conditional Breakpoints  (599 Views)
Create New Account