RAD Studio VCL Reference
TThread.Queue Method (TThread, TThreadMethod)

Asynchronously executes a method call within the main thread.

procedure Queue(AMethod: TThreadMethod); overload;
procedure Queue(AThreadProc: TThreadProcedure); overload;
class procedure Queue(AThread: TThread; AMethod: TThreadMethod); overload;
class procedure Queue(AThread: TThread; AThreadProc: TThreadProcedure); overload;
__fastcall Queue(TThreadMethod AMethod);
__fastcall Queue(TThreadProcedure AThreadProc);
__fastcall Queue(TThread AThread, TThreadMethod AMethod);
__fastcall Queue(TThread AThread, TThreadProcedure AThreadProc);

Queue causes the call specified by AMethod to be executed using the main thread, thereby avoiding multi-thread conflicts. The current thread is passed in the AThread parameter.  

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.

Warning: Do not call Queue from within the main thread. This can cause an infinite loop.
Note: You can also protect unsafe methods using critical sections or the multi-read exclusive-write synchronizer.


Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!