Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting watches in Visual Studio while debugging?

Posted on 2014-12-04
4
Medium Priority
?
150 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 668 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 664 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 668 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

721 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