Code of the day:
Code of the day:
procedure TForm1.Button1Click(Sender: TObject);
var
aTask: ITask;
begin
aTask := TTask.Create (procedure ()
begin
sleep (3000); // 3 seconds
ShowMessage ('Hello');
end);
aTask.Start;
end;
From http://docwiki.embarcadero.com/RADStudio/Berlin/en/Using_TTask_from_the_Parallel_Programming_Library
http://docwiki.embarcadero.com/RADStudio/Berlin/en/Using_TTask_from_the_Parallel_Programming_Library
procedure TForm1.Button1Click(Sender: TObject);
var
aTask: ITask;
begin
aTask := TTask.Create (procedure ()
begin
sleep (3000); // 3 seconds
ShowMessage ('Hello');
end);
aTask.Start;
end;
From http://docwiki.embarcadero.com/RADStudio/Berlin/en/Using_TTask_from_the_Parallel_Programming_Library
http://docwiki.embarcadero.com/RADStudio/Berlin/en/Using_TTask_from_the_Parallel_Programming_Library
Ok now I remember that calling Sleep(0) it's fine because you are telling the OS that your thread relinquish it's time slice and it should schedule for another thread that might be waiting
ReplyDeleteSleep(0) isn't the recommended way to do it though.
ReplyDeletehttp://joeduffyblog.com/2006/08/22/priorityinduced-starvation-why-sleep1-is-better-than-sleep0-and-the-windows-balance-set-manager/
quality.embarcadero.com - Log in - Embarcadero Technologies
ReplyDeleteThread task example suggests direct call to VCL