thread Synchronize method
Return to Introduction  Previous page  Next page
Applies to
acThread component.  

Declaration
procedure Synchronize(Method: TThreadMethod);  

Description
The Synchronize method executes a method call within the main VCL thread. Synchronize causes the call specified by Method to be executed using the main VCL thread, thereby avoiding multi-thread conflicts. If you are unsure whether a method call is thread-safe, call it from within the main VCL thread by passing it to the Synchronize or SynchronizeEx methods.  
 
tip Execution of the thread is suspended while Method is executing in the main VCL thread.  

Example
procedure TForm1.SynchronizedOutput;  
begin  
  OutputBox1.Items.Add(Variable1);  
  Label1.Caption := Variable2;  
end;  
 
procedure TForm1.acThread1Execute(Sender: TObject);  
begin  
  // don't try to make the asynchronous output to the main form's thread.  
  // Do only long-time calculations, then ñall Synchronize method  
  //...  
  StrVariable := StrData1;  
  IntVariable := IntData2;  
  Synchronize(SynchronizedOutput);  
  //...  
end;  

See also
SynchronizeEx, Execute, Suspend, Resume and Terminate methods;  
OnSynchronization event.