Is there a tool for Visual Studio to track (or interrupt) the value of a variable?

Is there a tool or parameter in the Visual Studio debugger to stop at breakpoints or when the variable is set to a specific value? I mean, if I know that the value will be set to "HELLO", I want the debugger to stop just as if it had reached a breakpoint?

+4
source share
5 answers

You are looking for a conditional breakpoint .

+9
source
  • Set a breakpoint anywhere in the code.
    • Include a list of breakpoint windows by going to Debug → Windows → Breakpoints.
    • In the breakpoints window, right-click the breakpoint
    • Select a condition ...
    • Enter any expression with your variable

The breakpoint will hit when the condition is met.

By right-clicking on the menu of breakpoints, you can also set breakpoints:

  • Only from certain processes or threads
  • By the number of visits
  • Only when changing a condition or variable
+8
source

there are observation points.

+4
source

Daves answers.

And I will add that you can just add an if statement containing a couple of dummy statements, and you put a breakpoint in it. He does the same.

Typical Usage:

if (i == 250) { int dummy = 2+2; //breakpoint here } 

In your case, since you are looking at the value of a string (assuming C ++ strings)

 if (mystring == "hello") { int dummy = 2+2; //breakpoint here } 
+3
source

try System.Diagnostics.Debug.Assert(yourVariable <> "HELLO") , and then click the Cancel button to start debugging. This works for ASP.net and Silverlight projects.

0
source

All Articles