반응형

 

Freeze and thaw thread execution

You can freeze and thaw, or suspend and resume, threads to control the order in which the threads perform work. Freezing and thawing threads can help you resolve concurrency issues, such as deadlocks and race conditions.

 Tip

To follow a single thread without freezing other threads, which is also a common debugging scenario, see Get started debugging multithreaded applications.

To freeze and unfreeze threads:

  1. In the Threads window, right-click any thread and then select Freeze. A Pause icon in the Current Thread column indicates that the thread is frozen.
  2. Select Columns in the Threads window toolbar, and then select Suspended Count to display the Suspended Count column. The suspended count value for the frozen thread is 1.
  3. Right-click the frozen thread and select Thaw.
  4. The Pause icon disappears, and the Suspended Count value changes to 0.

 

 

Switch to another thread

You may see a The application is in break mode window when you try to switch to another thread. This window tells you that the thread does not have any code that the current debugger can display. For example, you may be debugging managed code, but the thread is native code. The window offers suggestions for resolving the issue.

To switch to another thread:

  1. In the Threads window, make a note of the current thread ID, which is the thread with a yellow arrow in the Current Thread column. You'll want to switch back to this thread to continue your app.
  2. Right-click a different thread and select Switch To Thread from the context menu.
  3. Observe that the yellow arrow location has changed in the Threads window. The original current thread marker also remains, as an outline.
  4. Look at the tooltip on the thread marker in the code source editor, and the list in the Thread dropdown on the Debug Location toolbar. Observe that the current thread has also changed there.
  5. On the Debug Location toolbar, select a different thread from the Thread list. Note that the current thread changes in the other two locations also.
  6. In the source code editor, right-click a thread marker, point to Switch To Thread, and select another thread from the list. Observe that the current thread changes in all three locations.

With the thread marker in source code, you can switch only to threads that are stopped at that location. By using the Threads window and Debug Location toolbar, you can switch to any thread.

 

 

 

 

https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-use-the-threads-window?view=vs-2022&tabs=csharp 

 

Debug a multithreaded app - Visual Studio (Windows)

Debug using the Threads window and the Debug Location toolbar in Visual Studio

learn.microsoft.com

 

반응형

+ Recent posts