Show: Delphi
C++
Display Preferences
Assigning Separate Names to Similar Threads
From RAD Studio
Go Up to Executing thread objects Index
All thread instances from the same thread class have the same name. However, you can assign a different name for each thread instance at run time using the following steps.
To assign separate names to similar threads
-
Add a ThreadName property to the thread class by adding the following in the class definition:
property ThreadName: string read FName write FName; __property AnsiString ThreadName = {read=FName, write=FName};
__property AnsiString ThreadName = {read = FName, write = FName};
-
In the SetName method, change where it says:
ThreadNameInfo.FName := 'MyThreadName'; info.szName = "MyThreadName";
info.szName = "MyThreadName";
to:
ThreadNameInfo.FName := ThreadName; info.szName = ThreadName;
info.szName = ThreadName;
To create the thread object
- Create it suspended. See Executing Thread Objects.
- Assign a name, such as:
MyThread.ThreadName := 'SearchForFiles';
MyThread.ThreadName="SearchForFiles";
- Resume the thread. See Starting and Stopping Threads.