uses TlHelp32; {* Levanta a quantidade de Threads de um processo @param piPID Identificador do processo em questão } function TGInfoWinService.GetThreadCount(piPID: Cardinal): Boolean; var hSnapShot : THandle; rThreadInfo : TThreadEntry32; bNext : Boolean; iThreadCount: Integer; begin Result := False; iThreadCount := 0; try try hSnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0); if (hSnapShot = THandle(-1)) then raise EGWinService.Create('Erro ao levantar ThreadCount',39248209); rThreadInfo.dwSize := SizeOf(rThreadInfo); bNext := Thread32First(hSnapShot,rThreadInfo); while (bNext) do begin if (rThreadInfo.th32OwnerProcessID = piPID) then Inc(iThreadCount); bNext := Thread32Next(hSnapShot,rThreadInfo); end; Result := True; except on E: Exception do GerarLogTipoException(56565654,E,'Unt_WinService'); end; finally CloseHandle(hSnapShot); if Result then Self.FThreadCount := iThreadCount else Self.FThreadCount := -1; end; end;
Mais informações em:
http://balaiotecnologico.blogspot.com/2009/10/obtendo-informacoes-sobre-as-threads-de.html