Breakpoints

A breakpoint is one of the most important tools in debugging and is represented as a red dot in the preceding screenshot. When you start an application in debugging mode through the Debug menu, it runs sequentially through your code until it hits a breakpoint you have placed on any point in your code base, from which point you can choose to step into a code statement and inspect it, step over it, or step out of a set of statements.

A breakpoint will give you access to the actual values of your objects at that specific instance, which will help you inspect the behavior of your program at a point of concern, and therefore help you in troubleshooting whatever problem you may be having.

A program can have as many breakpoints as needed, and you are able to enable or disable these breakpoints in bulk.

There will be times when you may need Visual Studio to break only in a specific condition, such as when a property changes or some condition becomes true. Luckily, Visual Studio provides an out-of-the-box solution for this scenario. You are able to set what is normally referred to as a conditional breakpoint by right-clicking any normal breakpoint and then selecting Conditions. When you click on it, a pop up will appear where you can set your condition, as follows: 

The preceding screenshot is just a hypothetical example which shows how we can look at the LastName in a user model and check whether it is equal to our chosen string, "FUKIZI". In the preceding example, we set another condition called Hit Count >= 2, which means that our conditional breakpoint will only trigger after it has been hit two or more times.

We could also set an action to output a message or choose whether we want the execution to continue. Sometimes, we may need to look back on what was really happening before a certain point is reached. For this, the call stack comes in handy.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.21.152