This seems to be a WPF-specific issue.
If I set a breakpoint in the code, the program will pause when it reaches that line, and I can edit/add/remove code, and then continue - it runs the newly edited code (ie, it behaves as expected).
However, if I hit 'Break All', I get moved to window that says "Your App has entered a Break State...". If I try to edit my code, nothing happens. I try to type but nothing happens - no text appears, and there's no errors that pop up or anything.
I don't have this problem in WinForms applications - just WPF. If I create a basic WPF project from the template, I still have the issue.
It's a very frustrating issue! My ugly hacked solution is to add a button to my program's UI called 'Break', which executes a single line of code that has a breakpoint on it, basically recreating the behaviour that 'Break All' should have.
Weirdly, it's not an issue if I'm on a WPF project which uses multiple threads. Hitting 'Break All' in this case acts as if there's a breakpoint on the line of code where the background thread is set up.
I am not sure..but you can give a try.
To enable/disable Edit and Continue. In the Options dialog box, expand the Debugging node, and select Edit and Continue. In the Options dialog box Edit and Continue page, select or clear the Enable Edit and Continue check box. The setting takes effect when you restart the debugging session
source:https://msdn.microsoft.com/en-us/library/ms164926.aspx
Related
I'm using ReactiveUI in my WPF program, the WPF Window can be initialized and show normally, and I'm under Debug Mode,
but sometimes When I run some command code binding with button, it shows error below, and there're not more information, so I have no idea what's the reason to the Exception:
ReaciveUI.pdb contains the debug information required(...)
and after Continue, a window shows then the program was stopped:
An unhhandled Exception of type 'System.Exception' occured in ReactiveUI.dll
How to deal with this problem?
I found the keypoint of the problem later, the bug happens at
BtmCheckCmd = ReactiveCommand.CreateAsyncTask(
canBtmCheckCmd, //CanExecute
async _ =>//Execute
{
ProgressWinDow.RunCheckAndBarHandle();
MessageBox.Show("SomeThing");
}
I find a new way to check whrere the problem I former don't know so later I could found the solution.
In my case when the exception before happens, sometimes the messagebox show (sometimes not), then if the messagebox show, somtimes after click OK and the Exception Window Show, and if doing like this I can't find which part of my code does the problem haapen,
but if I click pause when the messagebox show(not click OK, but click pause under debug mode when msgbox show), then it go to the part of code it execute,
and by doing this I find the "Messagebox show" is in the code block of
async
in the part of code, and there're two method in async, so it should be the reason to this problem, maybe something wrong when async two method at the same time.
And In my case, the Messagebox is originally just used to test, so I delete the MessageBox and the problem solved.
Another way to find the problem in multi-thread is under debug mode,
and set the break points, then execute that part of code, when going into a break point, then go to the top ToolBar select :
Debug>>Windows>>Threads
then in the threads window can see what are the threads doing
In my case Visual Studio (2022) had locked a file.
To locate the locked file I did (in a console at the root of my project):
git clean -xfd
This gave me a message about several files which VS was locking.
But ultimately, the solution was to kill Visual Studio, perform a git clean, and then rebuild. You may also need to log out if on Windows to release the locked file(s) before rebuilding.
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:
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.
The output window in Visual Studio does not seem to be updating. When I manually switch the "Show output from" to any other option, then back to "Debug" it refreshes but otherwise, it does not refresh on its own. Does anyone know why this is occurring.
The commands System.Diagnostics.Debug.WriteLine() and SystemDiagnostics.Trace.WriteLine() both result in the same problem.
Are you familiar with Application.DoEvents();
Putting this immediately after your .WriteLines(); will allow the program to dispatch window events, otherwise you're simply going to see 'Not Responding' at the top of the screen. However, if you're displaying something in the interior of a detail loop, this will slow things down a lot. When it repaints the Trace screen, it's refreshing the entire window, not simply the line you just wrote.
I have a solution with some projects. There are several break-points in different projects. I want to trace the first thread hit one of these break-points and continue tracing that single thread despite of other threads entering the same code-blocks.
I know this is possible through defining a condition on the break-point, that is, thread name = ... or thread Id = ... but my case is a heavy loaded ASP.NET application and as soon as I attach to w3wp.exe many threads will hit the break-points. I need some thing like a ThreadLocal<break-point>.
Is it possible? If so, how?
Here's what I did:
Set a conditional break point that I
knew would only hit on the thread
that I was looking for.
Once the breakpoint hits and you are in the thread you want, in the Visual Studio Threads window (while debugging, Debug -> Windows -> Threads), Ctrl + A (to select all threads), and then Ctrl + click the thread you are currently on. You should have all threads except the one you want to debug selected.
Right-click, and choose "Freeze".
Now, Visual Studio will only step through the thawed thread. It seems to be much slower when doing this, presumably because it has to loop through all of the frozen threads, but it brought some sanity to my multi-threaded debugging.
Freeze/Thaw threads is an incorrect way because other threads don't execute any code.
The most correct and usable way is to:
Hit Ctrl+A in the breakpoints window (select all breakpoints).
Right click and select "Filter...".
Enter "ThreadId=(current thread id)".
In Visual Studio 2015 and newer, the process is similar:
Hit Ctrl+A in the breakpoints window (select all breakpoints).
Right click and select "Settings...".
Check "Conditions" and select "Filter" in the dropdown
Enter "ThreadId=(current thread id)".
So all threads are executed, but the debugger hits on the current thread only.
If multiple threads are being spawned as for a web application, #MattFaus answer's will not work. what I did instead is the following
Set up a breakpoint to interrupt the thread in the function I want.
Once the thread gets to the breakpoint and is paused, I remove the breakpoint and continue debugging using F8,F10 and F11, so that the others threads can run.
I have just released a Visual Studio 2010+ extension that does exactly what you are looking for.
And it's free :).
Presentation
This Visual Studio extension adds two shortcuts and toolbar buttons to allow developers to easily focus on single threads while debugging multi-threaded applications.
It dramatically reduces the need to manually go into the Threads window to freeze/thaw all threads but the one that needs to be followed, and therefore helps improve productivity.
Features
Restrict further execution to the current thread only. Will freeze all other threads. Shortcut: CTRL+T+T or Snowflake button.
Switch to the next single thread (based on ID). Will change current thread and freeze all other threads. Shortcut: CTRL+T+J or Next button.
Check it out here on the Gallery, on the official page or the Github repository.
A slightly different approach which I've used:
Create a normal breakpoint and let it get hit
Look in your threads window for the managed thread ID that you're current debugging
Right click your breakpoint in the breakpoints window and selecter filter
Enter ThreadId=xxx where xxx is the thread ID from 2
You can now debug without stopping other threads and without them hitting your breakpoint
This assumes you have time to do the above before a second thread hits your breakpoint. If not and other threads hit your breakpoint before you've done the above you can right click them in the threads window and choose freeze.
In VS 2019:
Set a breakpoint somewhere.
Hit F5 (Continue) until your thread comes.
Click on breakpoint to remove it.
You can step the thread with F10 or F11.
Set a Breakpoint Condition by right clicking the side bar of the line. Select "Condition" and enter the following with the name of your thread in quotes:
System.Threading.Thread.CurrentThread.Name=="name_of_your_thread"
Alternatively you can do the same by getting the thread's "Managed ID" from the "Threads" Window and use:
System.Threading.Thread.CurrentThread.ManagedThreadId==your_managed_thread_id
I would suggest adding another instance of the application on the live server, either on the same hardware or a new machine (cluster it) and then debug only that instance. I wouldn't add a breakpoint in code users are triggering. If that's not an option, I'd add more tracing.
However, if this is absolutely necessary and you need a solution stat, I'm sure you could add a breakpoint that breaks only if the request is coming from your IP address. You would do this by adding a conditional breakpoint that inspects HttpContext.Request.UserHostAddress. Note however that this slows down your application considerably.
If you don't want to stop all other threads (maybe you are attaching Visual Studio debugger to a running application that needs to answer to requests), you can use a macro that create and remove breakpoints automatically.
This is suggested in an answer to Stack Overflow question "Step over" when debugging multithreaded programs in Visual Studio.
However, the link only explain how to debug line by line. I suggest you modify the macro (if you're comfortable with it) to make it modify all breakpoints (in a given range of line for instance) to stop only on the current thread.
I think this is slightly different in Visual Studio 2015. They've changed a few things in the breakpoints, but here's how to apply the accepted answer from hzdbyte (above):
On the breakpoint in the coding margin, Right-Click > Conditions > Change from 'Conditional Expression' to 'Filter'. This then allows you to filter by ThreadId.
Alternatively on the breakpoint in the Breakpoints window, Right-Click > Settings > tick the Conditions box and do the above.
in VS2019, the conditional breakpoint is tid == xxxxx
this way the breakpoint will be hit only on that thread
TL;DR; Just press F5 when it jumps to the wrong thread.
I'm debugging a multithreaded queue processor in Visual Studio Pro 2022 Preview, I placed a breakpoint at a point where each queue item being processed would hit it. The IDE pauses because it hit the breakpoint. I press F10 (Step Over) a few times to step through the code. Then the another thread hit the breakpoint, and the IDE popped me over to that thread. I pressed F5 (Continue). The second thread continued processing, and the yellow debug-line returned to my original thread.