Posts Tagged ‘Parallel’

Updating the UI from a Task

While we’re talking things Parallel, the other part of the same demo from last post showed spawning a single task that slept for awhile and then called ShowMessage.

procedure TFormThreading.Button1Click(Sender: TObject);
var
  aTask: ITask;
  begin
    // not a thread safe snippet
    aTask := TTask.Create(procedure
                          begin
                            sleep(3000); 
                            ShowMessage('Hello');
                          end);
    aTask.Start;
 end;

Note the comment. Read On…