Reputation: 347
It is really annoying.
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mainForm()); <-- pausing visual studio breaks here.
Thanks guys.
Upvotes: 7
Views: 2443
Reputation: 11
Pressing Ctrl + F4 will close the newly opened Program.cs tab. Not a solution but it gets rid of it fast.
Upvotes: 1
Reputation: 1
I guess you are trying to make change (Edit and Continue) to a piece of code that may or may not be currently running. If it is not running placing breakpoint will not get you there. When you hit pause, VS opens Program.cs (because most of the time application is idle and sitting here) and hides code you wanted to modify.
Debugger is doing what is designed to do. Unfortunately there is no setting to change this behaviour and allow an exception (check Tools > Options >Debugging). The easiest thing to do is close Program.cs and you will end up exactly where you ware, before hitting pause.
Alternatively, write an application that runs in background and monitors VS activity and when it spots that Program.cs is open, close it. For this you will need API functions from "user32" such as FndWindow, GetWindowText etc. there are plenty of code samples showing how to 'spy' on and control another application.
Upvotes: 0
Reputation: 7856
Taking into account the previous comments, you might want to set a Breakpoint where you want your application to stop.
I usually do this by going to where I want the debugger to stop, then pressing F9
. You can also click in the left-hand margin. There are other ways.
You can also configure breakpoints to stop only when a certain condition is true (such as i == 0
).
Microsoft have a guide on Debugging in Visual Studio.
Upvotes: 0
Reputation: 5575
The debugger wil only pause there if your application is in an idle state (i.e it is actually executing Application.Run).
If you really don't wont to end up there, you might try using the 'DebuggerNonUserCode' attribute on the method that calls Application.Run, but I wouldn't recommend it.
Upvotes: 0
Reputation: 29345
@sramey are you sure pausing always breaks on the said line? If I may hazard a guess here I think when you press the pause button you application is idle and the program is spending most of its time in the Win32 message loop abstracted by Application.Run(). Hence there is a high probability that VS breaks the execution of the main thread there.
I think pressing pause is not always the best way of debugging things. You need to make educated guesses about problem areas and set breakpoints in relevant methods (like Constructors, API calls etc)
Need more info on what you are trying to accomplish here.
Upvotes: 3