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 ...