Megosztás a következőn keresztül:


How to: Specify a Breakpoint Condition

This topic applies to:

Edition

Visual Basic

C#

F#

C++

Web Developer

Express

Topic does not apply Topic does not apply Topic does not apply Topic applies Topic does not apply

Pro, Premium, and Ultimate

Topic applies

Topic applies

Topic applies

Topic applies

Topic applies

A breakpoint condition is an expression that the debugger evaluates when a breakpoint is reached. If the condition is satisfied, the debugger examines the How to: Specify a Hit Count to determine whether to break (or execute another specified action).

The condition can be any valid expression that is recognized by the debugger. In a banking program, for example, you could set a breakpoint condition such as balance < 0. For more information about valid expressions, see Expressions in the Debugger.

If you set a breakpoint condition with invalid syntax, a warning message appears immediately. If you specify a breakpoint condition with valid syntax but invalid semantics, a warning message appears the first time the breakpoint is hit. In either case, the debugger breaks execution when the invalid breakpoint is hit. The breakpoint is skipped only if the condition is valid and evaluates to false.

Note

The dialog boxes and menu commands you see might differ from those described in Help, depending on your active settings or edition of Visual Studio. To change your settings, on the Tools menu, click Import and Export Settings. For more information, see Working with Settings.

To specify a breakpoint condition

  1. In the Breakpoints window, right-click the line that contains a breakpoint glyph, and then click Condition on the shortcut menu.

    -or-

    In a source, Disassembly, or Call Stack, right-click a line that contains a breakpoint glyph, and then click Condition from Breakpoints on the shortcut menu.

  2. In the Breakpoint Condition dialog box, enter a valid expression in the Condition box, such as myLocalVariable > 1. For more information about valid expressions, see Expressions in the Debugger.

  3. Choose Is true if you want to break when the expression is satisfied, or choose Has changed if you want to break when the value of the expression has changed.

    Note

    The debugger does not evaluate the expression until the first time the breakpoint is reached. If you choose Has changed for native code, the debugger does not consider the first evaluation of the condition to be a change, so the breakpoint will not be hit on the first evaluation of the expression. If you choose Has changed for managed code, the breakpoint is hit on the first evaluation after Has changed is selected.

  4. Click OK.

See Also

Other Resources

Breakpoints and Tracepoints

Expressions in the Debugger