[Lazarus] TThread.Synchronize

Ondrej Pokorny lazarus at kluug.net
Tue Oct 25 13:28:21 CEST 2016


On 25.10.2016 13:21, LacaK via Lazarus wrote:
> I have form on which is button. When user clicks button OnClick event 
> handler is called (it is method of form). Processing of this method 
> takes some time say 1 minute.
> In the background is operating another thread which every 10 seconds 
> calls Synchronize(@MyForm.MyMethod).
>
> My understanding is that, Synchronize schedules execution of 
> MyForm.MyMethod to main thread, so method is not executed until 
> control is returned from event handler in MyForm. Right?

If you don't call CheckSynchronize within MyForm.MyMethod then yes.

> But in my case happens, that method is executed while execution of 
> event handler does not finished yet ... is it expected behavior ?
> If not is there any workaroud which enables me to hold thread until 
> event handler finishes ?

Check for Application.ProcessMessages and CheckSynchronize calls. These 
process synchronize queue, if I am not mistaken.

Ondrej


More information about the Lazarus mailing list