Step Through Visual Studio On Click - c#

I am trying to work on this website and I am a bit new to Visual Studio and whatnot. I would like to have a step through action whenever I click on certain icons on the website. Basically it is a lot of code, most of which I am learning, and I need to know where I am sending control when I click certian icons.
Any tips?

Insert break points in your code (click the left margin in the code windows). Your application will then stop, and you'll be sent to Visual Studio to do stuff when the code hits the break points. You also have functions to go through the app line by line from a break point when VS is in debug mode.

Well, the Button that you click must have a Click Event Handler in the code behind file. You can go to that code and add a break point by pressing F9 key or use Debug > Toggle Breakpoint, which makes debugger break when that line of code is executed, after which you can use F10 key or use Debug > Step Over to move debugger to next line after executing the current line. While debugging, you can use mouse hover to know values of variables.

Related

Break into debugger after next mouse click

When debugging a c# WPF application, is there a way to jump into the debugger immediately after the next mouse click?
Suppose I want to debug what happens when a certain button is pressed.
I can of course figure out what method is executed when the button is pressed, by analyzing the code and resource files, and then set a breakpoint at the start of this method. If I am not familiar with the code, this can take some time to figure out.
However it would be far easier and quicker if I could tell Visual Studio something like:
"Break execution, the next time user code is executed on the gui thread, after the next mouse click"
I.e. something like the "Break all" command (ctrl+alt+break), which does not break immediately, but waits for me to click the button and then break.
Is there a way to do this in Visual Studio?

Visual Studio 2012/C# breaks code execution, no breakpoint set

I'm having a problem in Visual Studio 2012/C# which is driving me crazy. I have a particular line of code in a C# file with NO breakpoint set. Every time this line should be executed the debugger interrupts the execution of my code like a breakpoint was set. The only difference i noticed is the arrow on the left hand side, indicating the current step. Usually this arrow is yellow (when a breakpoint is set). In my case it is grey.
I have been searching for a solution but did not find anything useful to this. I tried deleting all breakpoints, build project, rebuild project, clean project and it still appears.
Does anyone have the same problems and found a solution this?
normal arrow:
arrow in my case:
This line of code is currently executing, it calls something else, e.g. native code or .NET internal code and an exception happens there. You can see both arrows in the call stack window:
Perhaps you need to turn on "Show external code".
If you can't see the exception dialog, usually you can show it like this:

Visual Studio debugger - run until next user prompt

I'm in a Visual Studio debugging session, debugging a WinForms app, but I think this question applies to an ASP.Net code-behind debug session also. Let's say that I have lots of breakpoints set and I want to test a condition that requires running a setup test case first, then I want to run another test case that exercises the code again. The first time, I have to hit the Continue (F9) button 5 times to progress through the code breakpoints and finally arrive at the point where I'm prompted for input again. Now I want to input some data and I now want to carefully step through all the breakpoints.
Is there some way I can quickly push a button and tell the debugger to skip all those breakpoints during the setup test case entry and just progress to the next data input field? I know about the run to cursor capablilty, but that doesn't seem any easier than clicking thru all of the breakpoints.
I know this may sound trivial, but I find myself in this situation all the time.
I just want a super-continue button.
You can open the Breakpoints window (Debug -> Windows -> Breakpoints) and then you can select multiple breakpoints and disable or enable them as you go:
The best thing i can think of would be to create a condition on the breakpoint to only break when the data is set up.
E.g.
Or if all else fails, set a BreakPoint Hit Count, if you know it'll always be the 6th break that is relevant. E.g.

getting the debugger to break at the next click event

in a .net windows forms project which has 100s of forms, and all those forms has countless custom made controls with base classes involved, its very difficult for me to know where a particular button is, i mean whats the form name which I'm looking at while i'm running the application, and where exactly is the button click event, in code, of the button that I just clicked. Is there a debugging feature in Visual Studio, which would just break the execution for me to the line where the click happened. Can I tell VS to break at which ever Click event comes next?
(running visual studio 2012/13 these days).
thanks.
Just before you click the button in the program do this:
Go to visual studio and pause the program. Just press the pause button.
Then press F11 (Step Into).
Now press the button in the program, and you should be taken into the event handler.
For web projects, the technique suggested by Jakob Olsen will not really work, because you have no active thread in between the calls, and hence no thread to resume upon the next action. However what worked for me was:
Find some code (any code in your app) you know for sure it gets executed and set a breakpoint
Trigger this breakpoint, use SHIFT-F11 to step out until you're out of all methods
Now do the action of which you don't know what code is executed, and it will break
I can suggest partial solution.
If your click events are named like "Button_Click", open Breakpoints windows while in debug and create New breakpoint.
Click OK and you will see list of functions. Check them and click OK. On every function that you have selected will be created a breakpoint.

How to go back to a break point during debugging?

I am working in asp.net and debugging an application.
Sometimes there are scenarios in which I need to go back to a break point that I have passed. Is there any way to go back to that break point? I am debugging using F5 and F10 and press SHIFT+F5 to stop debugging.
I searched on google, but not finding the required answer.
Please guide me regarding this. I'll be thankful.
At least in Visual Studio 2010 you can drag the yellow arrow showing your current line you're debugging. It doesn't work all the times though.
I've used that if I had accidently passed a function I should have debugged.
If you have VS 2010 Ultimate IntelliTrace, by default, records breakpoint state. You can go back an examine the state at the breakpoint.
you can drag the yellow arrow which line u want debugging .

Categories