How to: Use the Threads Window
This topic applies to:
Pro and Team
Does not apply
Command or commands hidden by default.
With the Threads window, you can examine and manipulate threads in the program that you are debugging.
The Threads window contains a list of all the threads that currently exist in your program. For each thread, the list gives you certain useful information:
The Name and ID columns show the thread name and identification number, to help you identify threads.
The Priority column shows you the priority or precedence the system has assigned to each thread.
The Suspend column shows you the suspend count, which determines whether a thread is currently able to run. For an explanation of suspend count, see the section on Freezing and Thawing Threads in this topic.
The Category column classifies threads as user interface threads, remote procedure call handlers, or worker threads. This column also identifies the main thread.
The Location column shows the source location at which a thread is created.
The flag column is unlabelled and located on the extreme left. When you flag a thread that you want to study, a flag icon appears in this column. For instructions on how to flag threads, see How to: Flag and Unflag Threads.
Finally, there is another unlabelled column, which is second from the left. This is the active thread column. A yellow arrow in this column indicates an active thread.
To display the Threads window in break mode or run mode
- On the Debug menu, point to Windows, and then click Threads.
To sort the list of threads
In the Threads window, click the button at the top of any column.
To sort flagged threads to the top of the list, click the leftmost button.
To sort active threads to the top of the list, click the second button from the left.
To sort the threads with the lowest ID numbers to the top, click the ID button.
To sort threads by category, click the Category button. This sorts the threads into functional categories, which are sorted alphabetically.
To sort threads by name, click the Name button.
To sort threads by source locations, click the Location button.
To sort the highest-priority threads to the top, click the Priority button.
To sort the threads with the lowest suspend counts to the top, click the Suspend button.
If you want to reverse the sort order, click the same button again. If you sort by thread ID number, for example, the threads with the lowest ID numbers are sorted to the top. If you click the ID button again, the threads with highest ID numbers are sorted to the top.
To switch the debugging context to another thread
In the Threads window, right-click a thread, and choose Switch to Thread on the shortcut menu.
Double-click any thread.
A yellow arrow identifies the active thread.
Freezing and Thawing Threads
Threads can be frozen or thawed. When a thread is frozen, the system will not start execution of the thread even if there are resources available.
In native code, threads can be suspended or resumed by calling the Windows functions SuspendThread and ResumeThread or the MFC functions CWinThread::SuspendThread and CWinThread::ResumeThread. Calling SuspendThread or ResumeThread changes the suspend count, which is displayed in the Threads window. However, freezing or thawing a native thread does not change the suspend count. In native code, a thread cannot execute unless it is thawed and has a suspend count of zero.
In managed code, freezing or thawing a thread does change the suspend count. In managed code, a frozen thread has a suspend count of 1. In native code, a frozen thread has a suspend count of 0 unless the thread has been suspended by a SuspendThread call.
When you are debugging a call from native code to managed code, the managed code runs in the same physical thread as the native code that called it. Suspending or freezing the native thread freezes the managed code also.
To freeze execution of a thread
- In the Threads window, right-click a thread, and choose Freeze on the shortcut menu.
To thaw execution of a thread
- In the Threads window, right-click a frozen thread, and choose Thaw on the shortcut menu.
Displaying Thread Call Stacks and Switching Between Frames
In a multithreaded program, each thread has its own call stack. The Threads window provides a convenient way to view thread call stacks.
To view the call stack of a thread
In the Threads window, rest the mouse pointer in the active thread column on the line corresponding to the thread you want to study.
After a momentary delay, a DataTip appears. This shows the call stack for the thread.