Unit 'Classes' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#rtl]


[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

Abstract Thread class.


Source position: classesh.inc line 1904

type TThread = class



  TSystemTimes = record


Record for returning processor usage.

  IdleTime: QWord;


Processor idle time.

  UserTime: QWord;


User code execution time.

  KernelTime: QWord;


Kernel (OS) code execution time.

  NiceTime: QWord;


Nice (reduced priority) code execution time.



  procedure Execute; virtual; abstract;


Execute method. Must be overridden in a descendant thread.

  procedure Synchronize();


Synchronizes the thread by executing the method in the main thread.

  procedure Queue();


Queue a method for execution in the main thread.

  procedure ForceQueue();


Always queue a method for execution in the main thread.


  constructor Create();


Creates a new thread.

  destructor Destroy; override;


Destroys the thread object.

  class function CreateAnonymousThread();


Execute code in an anonymous thread.

  class procedure NameThreadForDebugging();


Set a thread name.

  class procedure SetReturnValue();


Set return value of a thread.

  class function CheckTerminated;


Check if the current thread has finished executing.

  class procedure RemoveQueuedEvents();


Remove methods scheduled for execution from queue.

  class procedure SpinWait();


Prevent thread execution in a spin-wait loop.

  class procedure Sleep();


Prevent thread execution.

  class procedure Yield;


Yield execution to other threads.

  class procedure GetSystemTimes();


Return CPU stats.

  class function GetTickCount; deprecated ;


Return tick count (32-bit).

  class function GetTickCount64;


Return tick count (64-bit).

  class function ExecuteInThread();


Execute a method or static procedure in a thread.

  procedure AfterConstruction; override;


Code to be executed after construction but before execute.

  procedure Start;


Starts a thread that was created in a suspended state.

  procedure Resume; deprecated ;


Resumes the thread's execution. Deprecated, see TThread.Start.

  procedure Suspend; deprecated ;


Suspends the thread's execution.

  procedure Terminate;


Signals the thread it should terminate.

  function WaitFor;


Waits for the thread to terminate and returns the exit status.

  property CurrentThread: TThread; [r]


Return current thread instance.

  property ProcessorCount: LongWord; [r]


Return the processor count for this system.

  property IsSingleProcessor: Boolean; [r]


Is the current system single processor or not.

  property FreeOnTerminate: Boolean; [rw]


Indicates whether the thread should free itself when it stops executing.

  property Handle: TThreadID; [r]


Returns the thread handle.

  property ExternalThread: Boolean; [r]


Is the thread instance an external thread ?

  property Priority: TThreadPriority; [rw]


Returns the thread priority.

  property Suspended: Boolean; [rw]


Indicates whether the thread is suspended.

  property Finished: Boolean; [r]


Has the thread finished executing.

  property ThreadID: TThreadID; [r]


Returns the thread ID.

  property OnTerminate: TNotifyEvent; [rw]


Event called when the thread terminates.

  property FatalException: TObject; [r]


Exception that occurred during thread execution.





Abstract Thread class.




Base class of all classes.


The TThread class encapsulates the native thread support of the operating system. To create a thread, declare a descendant of the TThread object and override the Execute method. In this method, the tthread's code should be executed. To run a thread, create an instance of the tthread descendant, and call it's execute method.

It is also possible to simply execute a method or static procedure in a thread using the TThread.ExecuteInThread class method.

See also



Thread error exception.



Execute method. Must be overridden in a descendant thread.



Execute a method or static procedure in a thread.

Documentation generated on: Jul 24 2023