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

...name a thread?

Previous pageReturn to chapter overviewNext page   

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
  inherited;  // <- this is important
 
  // ... actual thread's code goes there
end;
 
// ...

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

 

 

Option 2

Use BeginThreadEx function from EBase unit:

 

uses
  EBase; // for EBase
 
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);
  // ...
end;

 

 

Option 3

Use NameThread function from EBase unit:

 

uses
  Classes, // for TThread
  EBase;   // for NameThread
 
type
  TMyThread = class(TThread)
  protected
    procedure Execute; override;
  // ...
  end;
 
procedure TMyThread.Execute;
begin
  inherited;
  NameThread('My Thread, FileName=' + FileName);
 
  // ... actual thread's code goes there
end;

 

or:

 

uses
  EBase; // for NameThread
 
function MyThreadProc(Parameter: Pointer): Integer;
begin 
  NameThread('FileName=' + FileName);
 
  // ... actual thread's code goes there
end;
 
// ...
 
var
  TH: THandle;
  TID: Cardinal;
begin
  TH := BeginThread(nil, 0, MyThreadProc, nil, 0, TID);
 
  // ...
end;




Send feedback... Build date: 2018-11-26
Last edited: 2018-06-14
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