Solved

Setting watches in Visual Studio while debugging?

Posted on 2014-12-04
4
141 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now