Why is synchronization blocked by ShowModal?

I created a general thread class that controls the execution form, which is entered into the stream constructor and set as _progressForm. In the Execute method, the stream initializes the form and displays it using the ShowModal () function, as shown below:

procedure TProgressThread.Execute;
begin
  ...
  ShowForm;
end;

procedure TProgressThread.ShowForm;
begin
  if Assigned(_progressForm) then
  begin
    Synchronize(
      procedure
      begin
        _progressForm.ShowModal();
      end);
  end;
end;

What I cannot understand, why is my thread blocked in Synchronize? He does not return until the form of progress is closed. Should ShowModal block the main thread?

+4
source share
1 answer

TThread.Synchronize() synchronously . It blocks the calling thread until the synchronized code returns from the main thread.

ShowModal()also in sync . It blocks the calling thread until the form is closed.

, Synchronize() ShowModal() , Synchronize() , .

, TThread.Queue() TThread.Synchronize() TForm.Show() TForm.ShowModal().

. , , , . .

+11

Source: https://habr.com/ru/post/1686590/


All Articles