I have an application with 4 threads working the same code. However, when I step it jumps between the different threads. How can I lock it to one thread so the other threads
5. Step through one single thread without jumping around
How often are you debugging multithreaded code, when you hit your first breakpoint, take a step, and then suddenly you are stopped with the yellow arrow on another thread? The unexpected behavior comes from the breakpoint still being set and consequently being hit. By default, the debugger will stop on a breakpoint any time it is hit. This means that when you take a step, all threads are allowed to run, and one of your running threads hit this breakpoint before the step completes on your current thread. Next time you get in this situation try this:
- Disable or delete the breakpoint that has been hit by the new thread the debugger switched to.
- Press Continue (F5)
- Observe how your first initial step on that first thread completes and now is the active debugging context.
- Since your breakpoints are deleted or disabled, you can continue stepping on that single thread without interruption.
7 lesser known hacks for debugging in Visual Studio