Via Cà Matta 2 - Peschiera Borromeo (MI)
+39 02 00704272
info@synaptica.info

Delphi TThread Synchronization

Digital solution partner

Delphi TThread Synchronization

How to execute a method inside a TThread synchronously with the main Thread of the application is quite simple.

Suppose we want to synchronize access to a count variable, we can use the TThread.Synchronize and TThread.Queue methods.

The TThread.Syncronize method immediately executes the method interrupting the execution of the main Thread immediately while the TThread.Queue method should do a softer thing managing a queue of running methods.

However, be careful if you use TThread.Syncronize and TThread.Queue inside a console-type application “” and introduce a loop with the CheckSynchronize(100) method call to tell the main Thread to execute the queued methods.

The CheckSynchronize(100)  method is present in the System.Classes unit which must be included in the project.