thread name in the thread dialog 
Author Message
 thread name in the thread dialog

Hello,

I read somewhare that it is possible to give a name to a thread in order
to find it out easily in the thread dialog of msdev.

Does anybody know how to do it?

Thanx,

Serge Adda



Mon, 23 Dec 2002 03:00:00 GMT  
 thread name in the thread dialog

Quote:

> Hello,

> I read somewhare that it is possible to give a name to a thread in order
> to find it out easily in the thread dialog of msdev.

> Does anybody know how to do it?

> Thanx,

> Serge Adda

I saved this clipping, haven't tried it...

Date: Mon, 1 May 2000 13:28:49 +0200

Newsgroups: microsoft.public.vc.de{*filter*}

The following was on the handout
// Usage: SetThreadName (-1, "MainThread");
//
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

Quote:
} THREADNAME_INFO;

static void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName)
{
 THREADNAME_INFO info;
 info.dwType = 0x1000;
 info.szName = szThreadName;
 info.dwThreadID = dwThreadID;
 info.dwFlags = 0;

 __try
     {
  RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD),
(DWORD*)&info );
 }
 __except (EXCEPTION_CONTINUE_EXECUTION)
     {
 }

Quote:
}



Mon, 23 Dec 2002 03:00:00 GMT  
 thread name in the thread dialog

I used it once, but can't fine my reference now.
Try looking for "SetThreadName" (that was the method name) in some search
engine (Dejanews or the like).
This fires an exception, which the de{*filter*} will catch and use to name the
thread.

Gaddy

Quote:

>Hello,

>I read somewhare that it is possible to give a name to a thread in order
>to find it out easily in the thread dialog of msdev.

>Does anybody know how to do it?

>Thanx,

>Serge Adda



Fri, 27 Dec 2002 03:00:00 GMT  
 thread name in the thread dialog
Found it now (see below):

#define MS_VC_EXCEPTION 0x406d1388

typedef struct tagTHREADNAME_INFO
{
    DWORD dwType;        // must be 0x1000
    LPCSTR    szName;        // pointer to name (in same addr space)
    DWORD dwThreadID;    // thread ID (-1 caller thread)
    DWORD dwFlags;        // reserved for future use, most be zero

Quote:
} THREADNAME_INFO;

void SetThreadName(DWORD dwThreadID, LPCTSTR szThreadName)
{
    THREADNAME_INFO info;
    info.dwType = 0x1000;
    info.szName = szThreadName;
    info.dwThreadID = dwThreadID;
    info.dwFlags = 0;

    __try
    {
        RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD),
(DWORD *)&info);
    }
    except (EXCEPTION_CONTINUE_EXECUTION)
    {
    }

Quote:
}



Fri, 27 Dec 2002 03:00:00 GMT  
 thread name in the thread dialog

It works fine!!
Thanx,
Serge



Quote:
> Found it now (see below):

> #define MS_VC_EXCEPTION 0x406d1388

> typedef struct tagTHREADNAME_INFO
> {
>     DWORD dwType;        // must be 0x1000
>     LPCSTR    szName;        // pointer to name (in same addr space)
>     DWORD dwThreadID;    // thread ID (-1 caller thread)
>     DWORD dwFlags;        // reserved for future use, most be zero
> } THREADNAME_INFO;

> void SetThreadName(DWORD dwThreadID, LPCTSTR szThreadName)
> {
>     THREADNAME_INFO info;
>     info.dwType = 0x1000;
>     info.szName = szThreadName;
>     info.dwThreadID = dwThreadID;
>     info.dwFlags = 0;

>     __try
>     {
>         RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD),
> (DWORD *)&info);
>     }
>     except (EXCEPTION_CONTINUE_EXECUTION)
>     {
>     }
> }



Sun, 29 Dec 2002 03:00:00 GMT  
 thread name in the thread dialog
He is correct, there is an exception you can throw inside your thread
function,
a reference for this is in MS site somewhere, I can't locate my source, but
I've done it,
it was on a power point presentation in one of the vcdc conferences.

-tzurs.

Quote:

> I used it once, but can't fine my reference now.
> Try looking for "SetThreadName" (that was the method name) in some search
> engine (Dejanews or the like).
> This fires an exception, which the de{*filter*} will catch and use to name the
> thread.

> Gaddy


> >Hello,

> >I read somewhare that it is possible to give a name to a thread in order
> >to find it out easily in the thread dialog of msdev.

> >Does anybody know how to do it?

> >Thanx,

> >Serge Adda



Mon, 13 Jan 2003 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Doubt in dialog based threads in linux (UI threading)

2. MFC UI Thread doesnt start when COM method called in multi-threaded MFC dialog App

3. Doubt in dialog based threads in linux (UI threading)

4. threads, threads, and more threads

5. How do I name the main() thread?

6. How to set the Thread-Name in VC7

7. Getting thread names

8. Naming Threads in NT & Debuggin Apps

9. Reasonable thread name

10. How to name threads in VC++

11. CRichEditCtrl + named pipes + threads + stdin/stdout/stderr redirection

12. Naming Threads in an application

 

 
Powered by phpBB® Forum Software