Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#2

Re: Rausfinden, wie viele threads die eigene anwendung hat

  Alt 11. Jan 2004, 14:27
Beim Erstellen mitzählen? Oder so:
Delphi-Quellcode:
uses tlhelp32;

function GetThreadCount(ProcID: Cardinal): integer;
var
  pe32: TProcessEntry32;
  SnapShot: THandle;
  NumThreads: Cardinal;
begin
  NumThreads := 0;
  SnapShot := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, ProcID);
  if SnapShot <> INVALID_HANDLE_VALUE then
  try
    pe32.dwSize := SizeOf(ProcessEntry32);
    if Process32First(SnapShot, pe32) then
      NumThreads := pe32.cntThreads;
  finally
    CloseHandle(SnapShot);
  end;
  result := NumThreads;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(IntToStr(GetThreadCount(0))); // 0: current process
end;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat