Solved

Setting watches in Visual Studio while debugging?

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 1 28
"Emulate" TAB key when press Enter Key 3 49
Need syntax help building hyperlink 2 27
VB.net Code to make a TaskPane float in Excel Add-in 2 11
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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