Delphi-Quellcode:
procedure TForm1.A;
begin
while FThreadsActive do
begin
sleep(10);
end;
end;
procedure TForm1.B;
var
i: Cardinal;
begin
while FThreadsActive and not TThread.CurrentThread.CheckTerminated do
begin
sleep(50);
inc(i);
TThread.Queue(TThread.CurrentThread, procedure
begin
edit1.Text := format('%d %d',[integer(TThread.CurrentThread), i]);
end);
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FThreadsActive := False;
end;
So von Prinzip her, ich würde die FThreadsActive dann aber nur mit Interlocked/Atomic Funktionen anfassen.