Code: Alles auswählen
constructor TProgressThread.Create(aParent:TBruteForce);
begin
inherited Create(true);
FreeOnTerminate:=true;
FLastProgress:=0;
FParent:=aParent;
Resume;
end;
procedure TProgressThread.Execute;
begin
while not Terminated do
begin
if FLastProgress<>FParent.Progress then
begin
FLastProgress:=FParent.Progress;
Synchronize(@DoUpdate);
end;
end;
end;
procedure TProgressThread.DoUpdate;
begin
if assigned(OnProgress) then OnProgress(nil,FLastProgress); //OnProgress wird auf die Mainform umgelenkt und zeichnet dort in den Statusbar
end;
procedure TBruteForce.Run;
...
with TProgressThread.Create(self) do
try
MyProcThreadPool:=TProcThreadPool.Create;
try
MyProcThreadPool.DoParallel(@RunParallel,0,FProcessing.Count-1,nil);
finally
MyProcThreadPool.Free;
end;
finally
Terminate;
end;
...
end;
procedure TBruteForce.RunParallel(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem);
begin
FProgress:=round((index/FProcessing.Count)*100); //property Progress:byte read FProgress;
TOperation(FProcessing[index]).Run;
end;