Solved

Setting watches in Visual Studio while debugging?

Posted on 2014-12-04
4
147 Views
Last Modified: 2014-12-05
I'm not real sure how the "Watches" work in VS. I always thought that you could specify a variable/object to watch and then when the value changes, the program would go into debug mode and stop at the point of change without having to set any breakpoints. Is this correct? If so, I'm doing something wrong somewhere. If not, what is the correct way to utilize "Watches"?

Thanks!
0
Comment
Question by:BlakeMcKenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 14

Assisted Solution

by:brendanmeyer
brendanmeyer earned 167 total points
ID: 40482027
watches are used when you are already in debug mode,  when it pauses, or when you step through the code

Although you can set Conditional Breakpoints in the code,
set a normal breakpoint, and then right click the circle, and you can change it to conditional, ans set the conditions
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 166 total points
ID: 40482186
A Watch is not a way to break your code. It is simply a tool to easily see the values of variables and expressions when you pause the program in Debug mode or when a runtime error is encountered when running the program from Visual Studio.

You can also do this in other ways, such as moving the cursor over the variable or using data tips. But the watches have the advantage that you can see their values even when the code containing the variable or the expression is scrolled off the screen.

They enable you to easily give a look at the content of an array or some complex structures such as a DataTable.

You can also use them to change the value of a variable during a Debug session, which can be useful for some debugging or analysis situations.

Because you can have up to 4 watch windows (through the Debug menu while in Debug mode), you can also group them, enabling you as an example, to have all your database watches in one window and all the variables dealing with the form you are currently working on in another one,

But they cannot be used as breakpoints. Breakpoints have to be set manually or through code (with the Debug.Assert command). Manually, you set them by clicking in the grey margin at the left of the line on which you want to stop. As pointed to by brendanmeyer, you can set conditions through a right click on the breakpoint after it has been set. You can define that a breakpoint will trigger only if a value has changed since the last time a specific line is executed.

But there is no way to set a breakpoint "when a value change", that is to automatically break at the point where the change occurs. This is bad, because such a feature was available in the 90's in VB classic. I miss that feature a lot. But you have to understand that VB6 was interpreted while VB.NET is compiled when running in the debugger. It's easy for an interpreter to see if a variable change on a given line. Debugging would probably become a pain (very slow) if it was implemented in an environment where compiled code is running.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 167 total points
ID: 40482295
But there is no way to set a breakpoint "when a value change", that is to automatically break at the point where the change occurs. This is bad, because such a feature was available in the 90's in VB classic.
Er, if you have to know the instant a variable changes, and you don't know what code is executing the change, then you have a bad design. If you have so many places in your class that can update a variable that you cannot make sense of which place is updating the value, then you should probably introduce a property which sets the value, and then update the variable via the property--at least then you can break in the property's setter, and you'll be able to inspect call stack at that point.
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40482768
Thank you...
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question