How to Debug a Single Thread in Visual Studio

How to debug a single thread in Visual Studio?

Freeze/Thaw threads is an incorrect way because other threads don't execute any code.

The most correct and usable way is to:

  1. Hit Ctrl+A in the breakpoints window (select all breakpoints).
  2. Right click and select "Filter...".
  3. Enter "ThreadId=(current thread id)".

In Visual Studio 2015 and newer, the process is similar:

  1. Hit Ctrl+A in the breakpoints window (select all breakpoints).
  2. Right click and select "Settings...".
  3. Check "Conditions" and select "Filter" in the dropdown
  4. Enter "ThreadId=(current thread id)".

So all threads are executed, but the debugger hits on the current thread only.

Is there a way to debug multithreaded applications in singletreaded mode in Visual Studio?

Is there a way to debug multithreaded applications in singletreaded
mode in Visual Studio?

Just as Dialecticus suggested, you could try these:

Suggestion

1) Use Threads Window

  • first, set a breakpoint at the entry of the main function

  • start debugging and then enter Debug-->Windows-->Threads--> then right-click on the threads that you do not want to debug and then select Freeze. And note that you have to always click on switch to thread, every time something happens.

  • You can refer to this document about using Threads Window.

2) you can try to follow this document to set a new breakpoint about the specific single thread ID to debug it.

3) there is also a vs extension called Debug Single Thread. You can also use it.

Visual Studio, debug one of multiple threads

Yes.

In the Threads window (Debug -> Windows -> Threads) right-click the thread you want and select "switch to thread".

You can also choose "freeze" on the threads you don't want to debug in order to keep them from running. Don't forget to "thaw" them if you expect them to do work, however.

Further reading.

.Net debugging: how to suspend only one thread?

While debugging open the thread window: Debug->Windows->Threads. Right-click on the thread(s) you want to suspend and select freeze. Use thaw to enable thread execution again.



Related Topics



Leave a reply



Submit