More on Testing and Debugging an ASP.NET 2.0 Application - How to use tracepoints
(Page 3 of 4 )
In addition to breakpoints, Visual Studio 2005 provides a new feature called
tracepoints. A tracepoint is a special type of breakpoint that performs an action when it’s encountered. Figure 4-10 shows how tracepoints work.
To set a tracepoint, you use the When Breakpoint Is Hit dialog box to indicate what you want to do when the tracepoint is encountered or “hit.” In most cases, you’ll use the Print a Message option to display a message in the Output window. As indicated in this dialog box, the message can include variable values and other expressions as well as special keywords.
For example, the message shown here will include the value of the SelectedValue property of the ddlProducts control. You can see the output from this tracepoint in the Output window in this figure. Here, the first tracepoint message was displayed the first time the page was requested. The second message was displayed when a product was selected from the drop-down list. And the third message was displayed when a quantity was entered and the Add to Cart button was clicked.
Notice that the Output window is also used to display Visual Studio messages like the first, second, and fifth messages shown in this figure. Because of that, this window is displayed automatically when you run an application. If you ever close it and want to reopen it without running the application, however, you can do that using the View->Output command.
To run a macro when a tracepoint is encountered, you select the Run a Macro option. Then, the drop-down list becomes available and you can select the macro you want to run from this list.
By default, program execution continues after the tracepoint action is performed. If that’s not what you want, you can remove the check mark from the Continue Execution option. Then, the program will enter break mode when the tracepoint action is complete.
After you set a tracepoint on a statement, the statement will be highlighted and a breakpoint indicator will appear in the margin. If program execution will continue after the tracepoint action is performed, the indicator will appear as a large diamond. If the program will enter break mode, however, the same indicator is used as for a standard breakpoint.
The Order page with a tracepoint and the dialog box used to set it

Figure 4-10. How to use tracepoints
Output from the tracepoint in the Output window

Description
How to work in break mode
Figure 4-11 shows the Order page in break mode. In this mode, the next statement to be executed is highlighted. Then, you can use the debugging information that’s available to try to determine the cause of an exception or a logical error.
For example, you can place the mouse pointer over a variable, property, or expression to display its current value in a data tip. You can also display the values of the members of an array, structure, or object. To do that, place the mouse pointer over the array, structure, or object to display its data tip, and then point to the plus sign in that data tip. In this figure, for example, you can see the current values of the members of the Product object named selectedProduct.
You can also use a data tip to change the value of a variable or property. To do that, just right-click the data tip and then choose Edit Value from the shortcut menu. When you do, the value that’s displayed will become editable so you can enter a new value.
You can also see the values of other properties and variables in the Autos window near the bottom left of the Visual Studio window. You’ll learn more about the Autos window and some of the other debugging windows in a minute.
The Shopping Cart application in break mode

Figure 4-11. How to work in break mode
Description
- When you enter break mode, the debugger highlights the next statement to be executed.
- You can use the debugging windows and the buttons in the Debug menu and toolbar to control the execution of the program and determine the cause of an exception.
- To display the value of a variable or property in a data tip, position the mouse pointer over the variable or property in the Code Editor window. To display a data tip for an expression, highlight the expression and then point to it. The expression must not contain a method call.
- To display the members of an array, structure, or object in a data tip, position the mouse pointer over it to display its data tip, and then point to the plus sign in the data tip.
- To change the value of a variable in a data tip, right-click the data tip, choose Edit Value, and then enter the new value.
- To continue program execution, press F5 or click the Continue button in the Standard or Debug toolbar. For more options about controlling program execution, see figure 4-12.
Next: How to control the execution of an application >>
More ASP.NET Articles
More By Murach Publishing
|
This article is excerpted from chapter four of the book Murach's ASP.NET 2.0 Web Programming with VB 2005, written by Joel Murach and Anne Boehm (Murach, 2006; ISBN: 1890774324). Check it out today at your favorite bookstore. Buy this book now.
|
|