Windows messages

 The first method works by sending Windows messages to the main thread. As the name suggests, it is limited to the Windows operating system. I'll show two ways to achieve the same result. The first works only in VCL applications, while the second also works with FireMonkey.

Before the tasks are started, the code initializes the result FValue to zero so that partial results can be aggregated correctly. It also sets the variable FNumDone to zero. This variable counts the tasks that have completed their work:

procedure TfrmIncDecComm.btnMessageClick(Sender: TObject);begin  FValue := 0;  FNumDone := 0;  RunInParallel(IncMessage, DecMessage);end;

Both tasks are implemented in the same way, so I'll only show one method here. IncMessage ...

Get Delphi High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.