Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This topic applies to:
| Edition | Visual Basic | C# | C++ | Web Developer | 
|---|---|---|---|---|
| Express | .gif) | .gif) | Native only | .gif) | 
| Standard | .gif) | 
 | Native only | 
 | 
| Pro and Team | .gif) | 
 | Native only | 
 | 
Table legend:
| .gif) | Applies | 
| .gif) | Does not apply | 
| .gif) | Command or commands hidden by default. | 
To set a thread name in your program, use the SetThreadName function, as shown in the following code example.
Example
//
// Usage: SetThreadName (-1, "MainThread");
//
#include <windows.h>
const DWORD MS_VC_EXCEPTION=0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
   DWORD dwType; // Must be 0x1000.
   LPCSTR szName; // Pointer to name (in user addr space).
   DWORD dwThreadID; // Thread ID (-1=caller thread).
   DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
void SetThreadName( DWORD dwThreadID, char* threadName)
{
   THREADNAME_INFO info;
   info.dwType = 0x1000;
   info.szName = threadName;
   info.dwThreadID = dwThreadID;
   info.dwFlags = 0;
   __try
   {
      RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
   }
   __except(EXCEPTION_EXECUTE_HANDLER)
   {
   }
}
See Also
Tasks
How to: Set a Thread Name in Managed Code