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:
- 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.
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
How to Avoid Multiple Instances of Windows Form in C#
How to Make My Windows Form App Snap to Screen Edges
C# - How to Iterate Through Classes Fields and Set Properties
The Source File Is Different from When the Module Was Built
Spinwait VS Sleep Waiting. Which One to Use
How to Write Super-Fast File-Streaming Code in C#
Embedding a File Explorer Instance in a Windows Forms Application Form
Owin's Getexternallogininfoasync Always Returns Null
Are Protected Members/Fields Really That Bad
How to Unit Test with Ilogger in ASP.NET Core
How to Add an Ampersand for a Value in a ASP.NET/C# App Config File Value
Why Is There Huge Performance Hit in 2048X2048 Versus 2047X2047 Array Multiplication
How to Sort Depended Objects by Dependency
How to Auto Resize and Adjust Form Controls with Change in Resolution
How to Convert a Datetime to the Number of Seconds Since 1970
Which Is Better Between a Readonly Modifier and a Private Setter
When to Use a Sortedlist<Tkey, Tvalue> Over a Sorteddictionary<Tkey, Tvalue>