if 1 process needs 10ms, 1 div 10 = needs wait 10ms to show the resulted!
TTask.WaitForAll(Tasks); --> wait for "ALL" before show the resulted!
now, if you use "WaitForANY(...)", then, the resulted is showed at first and dont wait for rest...
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
try use "IFUTURE" (instead ITask) for catch the resulted like this!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
fixing..... sorry my fault!!!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
MyText: string; XValue: TStringList; begin SumValue := 0; SetLength(Tasks, 10); // (Sender as TButton).Enabled := False; // ElapsedTime := GetTickCount; // XValue := TStringList.Create; try for I := 0 to 9 do begin Tasks[I] := TTask.Create( procedure() var ThreadedI: Integer; GTick: cardinal; ID: string; begin ID := TThread.CurrentThread.ThreadID.ToString; GTick := GetTickCount; for ThreadedI := 0 to (1000000 - 1) do begin TInterlocked.Add(SumValue, 1); end; // XValue.AddPair(ID, (GetTickCount - GTick).ToString); end); end; // for I := 0 to Pred(10) do Tasks[I].Start; // Start Created Thread // TTask.WaitForAll(Tasks); ElapsedTime := GetTickCount - ElapsedTime; // MyText := ''; for var MyItem in XValue do MyText := MyText + MyItem + sLineBreak; // ShowMessage(MyText);
此帖子包含附件: 大小:15.0K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3