Search code examples
c#debuggingvariablesvisual-studio-expresswatch

How do I "run until this variable changes" when debugging?


When debugging my C#, I often want to know when a variable's value changes and then investigate the state of the program.

Currently, I do it like this:

  1. Watch-list the offending variable.
  2. Physically spam F10 (shortcut for Step Over) until I see the value change.

However, the number of F10s required is annoying.

Surely this has been automated, I thought. But I cannot find this feature in my Microsoft Visual C# Express, which surprises me. After all, the Watch-list does automatically highlight changed values in bright red.

Am I missing something?


Solution

  • Simple trick for Express edition:

    private string myValue;
    public string MyValue
    {
      set
      {
        if (this.myValue != value) Debugger.Break();
        this.myValue = value;
      }
    }