Search code examples
multithreadingdelphisynchronize

Do we have to use Synchronize if we want to make some changes in the VCL main thread?


Let's say that I want to simply change the caption of a Label when the program is in a child thread. I don't want use Synchronize. I really don't want to get the OS switch to another thread context to do this job. I know that I can't do this by just putting some lock(Semaphore or something) in my child thread. Can anyone tell me the reason why I can't use locks for that? Thanks in advance :)


Solution

  • Do we have to use Synchronize if we want to make some changes in the VCL main thread?

    Yes.

    Well, code that accesses VCL objects has to execute on the main thread and Synchronize is the most commonly used way to achieve that. There is no way around that constraint.