I have multiple Form Application in C#, I want to debug current running Form button event with the specific line, as in the Visual Basic 6 current running Form is debug with pressing short key Ctrl+Break. Then press the button or place on the form to start the debugging process where I want.
Is there any debugging method in C# like Visual Basic 6 short key Ctrl+Break ?
Just click the line which is you suspect and press f9 it put a breakpoint and then you can use:
Step Into f11 : line by line debugging
Step Over f10 : without debugging each line it just return result
And other tactic to learn use Console.WriteLine() in form application also. In output window you can see whatever write in writeline.
Also if you want to see variable's value, you can use watch window.
To debug the code in Visual Studio, specify the breakpoint (by clicking the left side of line code) and then press the F5 key. Use F10 key to continue with step by step debugging.
Related
I am working with Visual Studio 2015.
I have a big c# class file with lot of properties and methods. I want to set breakpoints to all possible lines (set and get of properties, methods) at once. How can I do that?
You could add Debugger.Break() on the end of every single line. Therefore you could use the search and replace function of visual studio and replace \n with Debugger.Break()\n (Remember activating the regular expression option). This would cause the debugger to break at every single line, even though you won't have an indicated breakpoint.
I don't think that there's a method to add normal vs breakpoints to every single line though, due to the fact that it's quite useless, considering that you normally just step through the code with F11.
I think you are looking for this,
steps to follow:
1) Add a break point on the first line of code you want to debug.
2) Run the application.
3) When you want to run the next line of code, Select Debug | Step Into
4) Repeat step #3 for each line of the code
With vim (vsvim) you can set a breakpoint, move down a line, then repeat however many times you like, eg:
{Escape}qq:vsc Debug.ToggleBreakpoint{Enter}jq100#q
will set breakpoints on the next 100 lines
edit: here is example video, wouldnt let me embed gif https://imgur.com/SFhlEr7
Step Into(F11) or use the Debugger.Break() or add breakpoint directly would be the workarounds for you, of course, I suggest you use the Step Into(F11) which was much more convenient.
If you could use the latest VS2017 version, it has a new feature "Run to Click" which is also a better workaround for you during debugging.
Actually you don't have to debug every line code, that's also the reason I suggest you use this new feature.
Run to Click: Simply click the icon next to a line of code while debugging to run to that line. No longer set temporary breakpoints or
perform several steps to execute your code and stop on the line you
want. Now while stopped at a break state under the debugger, the Run
to Click icon subtly appears next to the line of code that your mouse
is hovered over. Move your mouse to the icon and click the button, now
your code will run and stop on that line the next time it is hit in
your code path. Turn it off from Debug> Options > Enable Run to
Click.
Reference:
https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes
Open a feature request with Microsoft https://learn.microsoft.com/en-us/visualstudio/ide/suggest-a-feature?view=vs-2022
There should be a mode that visual studio can be put in so that it automatically stops on every line of code in a particular project. This would be VERY valuable when you attach the debugger to a pre-existing process and you don't know where in the app is the current point of execution is, ie: web apps where you do not know the entry point.
From this post I got this:
For debugging a button click without setting breakpoints:
Start the app with the debugger.
Get to the state immediately before the intended click.
Go back to the debugger and press Pause then F11 (Step Into) -- nothing will happen.
Go to the app and press the button -- the debugger should take over and drop you into the event handler.
This is Not Working for me however it was working for me Before. Dont know why its very awesome but not working now. Anyone?
Please reset your VS settings, and then debug it again.
I just use a simple Winform app in my side:
https://onedrive.live.com/embed?cid=55E83A59BF9AE3EB&resid=55E83A59BF9AE3EB%21893&authkey=AEmhE8zHWfnS4gE
It works well using the following steps:
(1)Debug the app(F5).
(2)Click "Ctrl+Alt+Break", I will get the result like the following screen shot.
(3)Click F11(Step Into).
(4)Click the button1, it will hit a breakpoint in the button1 click event, and then using F11 step into. The same steps as the button2 event.
I just use the default VS settings with the latest VS2015 Enterprise version 14.0.25431.01 update 3. So you could test it using the above simple sample, it still has this issue in your side, maybe we could think about the VS settings and the VS setup.
I have a C# WPF Application code, which I want to understand. I am using f11 and f10 to step-in and step-over. However, once my application begins, I don't know which part of the code is executing.
Here is what I want:
I want to know which part of the code is getting executed even after the application begins and as and when I click on menu in the application, I want to see which part of code is being executed.
Please I am new to c# VS 2012 and WPF. Help me in analyzing the application code.
You have a few options:
Click Pause when running, and then Step Into. This will bring you to the line being called when you click on a button or menu item for example.
Set a break point at the point you want it to break.
Inside your code, place Debugger.Break() to stop the debugger at a specific line of code.
here are some steps you can follow.
Start your debugging from f10 not from F5. this will start you
application under debug mode but from start evetn from main method.
while runing application under debug mode you can use pause button to
peek into where your code is running right now.
Use F11 when you wish to go in to the code(code need to be in your source tree.) to see what calling function is doing.
Use mode Debug while following these steps.
I just wrote a clever program called helloworld. It's a C#/.NET 4.5 console app. Deep within the twisted nested mazes of logic there's use of Console.WriteLine().
When I'm running this at a command line, it runs and I see the output. I can do other commands and mess around a bit, and later scroll up to see the output again.
Now I'm in Visual Studio, tweaking the source ("Hi" is more efficient than "Hello") and testing by tapping F5. What happens is a console window pops up and immediately vanishes. I have no idea what the program printed. How can I see the output?
I don't want to modify my source at all. After searching for solutions, I find some who say to use Console.ReadKey() - but then it would suck to be using the program at the command line. There's no real reason the user should have to tap a key when the program has already done its work. Even if i go with this, there's the problem of the output disappearing when the console window closes after a key tap.
I don't want to use Debug.WriteLine() which does write to the output window in VS, but doesn't write ordinary output for the end user to see.
I have discovered ctrl-F5, which runs the program as if it had a final Console.ReadKey() line, but there's still the problem of when I tap any key, all the output vanishes along with the window. Three minutes later, I'm thinking "Oh wait, did it print 'Hello' or 'Helo'?" No way to check.
Seems like the Visual Studio IDE should somehow capture all that a freshly built program writes to its stdout or the Microsoft equivalent thereof, and show it in its "Output" panel, or some panel, for later scrutiny. Maybe it does do this, and I don't yet know the trick to it? Seems like this would be a common desire among millions of C# developers.
If you're working on a .NET Core console application (or .NET Framework via the .NET SDK) using Visual Studio 2019, the behaviour of leaving the console window open after the program has executed will now happen by default:
Specifically:
This should prevent the need to add Console.Read() calls to console apps to prevent the console window from closing immediately after the program has finished executing. The launched console window is also re-used for subsequent runs, so if you’re used to using ctrl+f5, you won’t have lots of console windows to close after you’ve launched your application a few times.
The reason it closes automaticly is because it's done running the program. If you want to see what it did, make it need a new command like hitting any key. The Console.ReadKey(); pauses it and waits for a User to hit a key to continue. Put that command after the commands of instruction you are doing and it will pause it until you hit any key.
Console.ReadKey(); // Pauses until you hit any key
You can also run your program pressing F10 (executes one line by one), with F11 (goes inside a function).
The other option you have is to set breakpoints in Visual Studion and run the program by pressing F5 - it will stop at the next breakpoint. And the breakpoints can have conditions - i.e. conditional breakpoints.
Some options are:
1. wrap #if DEBUG around Console.ReadKey()
2. run directly from an open terminal
3. create a Test project - but again you'll need Console.ReadKey() to stop it closing.
When a breakpoints hits, the VS window is showed automatically and points to the line with the breakpoint. For my case that's not helping. Is it possible to prevent the VS studio window from showing when the breakpoint hits ? Thanks
EDIT: he problem is that I'm reading from a barcode scanner gun. While reading, the breakpoint hits thus switching to the VS window and some portion of the barcode is printed in the source file :) That's why I don't want it to switch to the VS window
If you set the breakpoint in the Visual Studio, you can change it to "tracepoint" by specifying "Continue execution" as "When hit".
If the breakpoint is present in the executable, it can be disabled as described in How to disable a programmatical breakpoint / assert?
You can start your application as Start Without Debugging or use (Ctrl + F5) for that.
Or If you want to debug, but not for a condition, you can provide the condition on breakpoints when to hit.