Root > How to... > ...name a thread?

...name a thread?

Previous pageReturn to chapter overviewNext page   

Important Hint: It is recommended to use EurekaLog's naming routines instead of RTL (and possibly other frameworks), because EurekaLog supports Get/SetThreadDescription API, while RTL does not.

 

Option 1

Derive your thread class from TThreadEx class from EBase unit:

 

uses
  EBase; // for TThreadEx
 
type
  TMyThread = class(TThreadEx) 
  protected
    procedure Execute; override;
  end;
 
procedure TMyThread.Execute;
begin
  // ... actual thread's code goes there
end;
 
// ...

 
  Thread := TMyThread.Create(

    'My Thread, FileName=' + FileName { <- this is just an example });
  // or
  Thread := TMyThread.Create(False { <- suspended? }

    'My Thread, FileName=' + FileName { <- this is just an example });

 

 

Option 2

Use BeginThreadEx function from EBase unit:

 

uses
  EBase; // for BeginThreadEx
 
function MyThreadProc(Parameter: Pointer): Integer;
begin
  // ... actual thread's code goes there
end;
 
// ...
 
var
  TH: THandle;
  TID: Cardinal;
begin
  TH := BeginThreadEx
    (nil, 0, MyThreadProc, nil, 0, TID
     'My Thread, FileName=' + FileName { <- this is just an example });
  // ...
end;

 

 

Option 3

Use NameThread (or NameThreadForDebugging) function from EBase unit:

 

uses
  Classes, // for TThread
  EBase;   // for NameThread and NameThreadForDebugging
 
type
  TMyThread = class(TThread)
  protected
    procedure Execute; override;
  // ...
  end;
 
procedure TMyThread.Execute;
begin
  NameThread('My Thread, FileName=' + FileName { <- this is just an example });
  // Alternatively:

  // NameThreadForDebugging('My Thread, FileName=' + FileName);
 
  // ... actual thread's code goes there
end;

 

or:

 

uses
  EBase; // for NameThread and NameThreadForDebugging
 
function MyThreadProc(Parameter: Pointer): Integer;
begin 
  NameThread('My Thread');

  // Alternatively:

  // NameThreadForDebugging('My Thread');
 
  // ... actual thread's code goes there
end;
 
// ...
 
var
  TH: THandle;
  TID: Cardinal;
begin
  TH := BeginThread(nil, 0, MyThreadProc, nil, 0, TID);
 
  // ...
end;

 

 

See also:




Send feedback... Build date: 2024-12-19
Last edited: 2023-03-07
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/how_to_name_thread.php