System.Classes.TThread.Queue

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure Queue(AMethod: TThreadMethod); overload; inline;
procedure Queue(AThreadProc: TThreadProcedure); overload; inline;
class procedure Queue(const AThread: TThread; AMethod: TThreadMethod); overload; static;
class procedure Queue(const AThread: TThread; AThreadProc: TThreadProcedure); overload; static;

C++

void __fastcall Queue(TThreadMethod AMethod)/* overload */;
void __fastcall Queue(_di_TThreadProcedure AThreadProc)/* overload */;
static void __fastcall Queue(TThread* const AThread, TThreadMethod AMethod)/* overload */;
static void __fastcall Queue(TThread* const AThread, _di_TThreadProcedure AThreadProc)/* overload */;

Properties

Type Visibility Source Unit Parent
procedure
function
public
System.Classes.pas
System.Classes.hpp
System.Classes TThread

Description

Executes a method call within the main thread.

Queue causes the call specified by AMethod to be asynchronously executed using the main thread, thereby avoiding multi-thread conflicts.

Warning: If the caller thread is the main thread, Queue executes the call directly (synchronously). In this case, use ForceQueue to queue the execution of a method call within the main thread.

AMethod associates the caller thread:

  • For static methods, you can associate the AMethod with any thread using the AThread parameter.
  • You can use nil/NULL as the AThread parameter if you do not need to know the information of the caller thread in the main thread.
  • RemoveQueuedEvents uses this thread information to find the proper queued method.

If you are unsure whether a method call is thread-safe, call it from within the Synchronize or Queue methods to ensure that it executes in the main thread.

Unlike Synchronize, execution of the current thread is allowed to continue. The main thread will eventually process all queued methods.

Note: You can also protect unsafe methods using critical sections or the multi-read exclusive-write synchronizer.

See Also

Code Examples