NameThread problem

delphi package - automated exception handling
Post Reply
mjs42
Posts: 2
Joined: Fri May 29, 2015 2:32 pm

NameThread problem

Post by mjs42 »

I can't get this to work.

...
NameThread(ThreadID, "Thread Instance descriptive name");

String sTest = GetThreadName(ThreadID);

....

Always returns "thread $xxxx"

I have multiple instances of a thread and was planning on using NameThread to set a better descriptive name in the bugreport. I'm using version 4.0.5

It there an addition set up I need. madExcept is enabled :wink:
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: NameThread problem

Post by madshi »

Just tested this in BCB XE8:

Code: Select all

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  HANDLE th;
  DWORD tid;
  th = CreateThread(NULL, 0, (unsigned long (__stdcall *)(void*)) ExitThread, NULL, CREATE_SUSPENDED, &tid);
  NameThread(tid, "Thread Instance descriptive name");
  Caption = GetThreadName(tid);
}
Works here. Maybe the threadID you were using didn't exist? The naming only works for threads which actually exist. Also, madExcept needs to be able to open the threadID ("OpenThread(threadId, SYNCHRONIZE or $40)").
mjs42
Posts: 2
Joined: Fri May 29, 2015 2:32 pm

Re: NameThread problem

Post by mjs42 »

It is actually acting like the NameThreadForDebugging method. It names the threads in the thread status window when running but I need it to log the name in the bug report. Unfortunately I'm stuck with BCB XE.

I place the call in several place to see if that affected anything. Placed call inside thread constructor, after thread creation, in thread execute, and after the start of the thread. All seems to log to the thread status window but names do not show in the bugreport file when I cause an exception.

Any ideas?

Thanks
Mike
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: NameThread problem

Post by madshi »

Does the code I posted work for you in a Button1Click event?

Maybe you can provide me with a simple test project?
Post Reply