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
NameThread problem
Re: NameThread problem
Just tested this in BCB XE8:
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)").
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);
}
Re: NameThread problem
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
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
Re: NameThread problem
Does the code I posted work for you in a Button1Click event?
Maybe you can provide me with a simple test project?
Maybe you can provide me with a simple test project?