Herhangi bir prosesin (işlem) bünyesinde bulunan thread (kanal) sayısını almak için aşağıdaki alt programı kullanabilirsiniz. GetCurrentProcessId çalışmakta olan programın prosess kimlik numarasını getirir. TlHelp32 ünitesini dahil etmeyi unutmayın.
implementation uses TlHelp32; function ThreadCount(iProcessID: DWord): integer; var SnapHandle: THandle; ProcEntry: TProcessEntry32; begin Result := 0; SnapHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if SnapHandle = 0 then Exit; FillChar(ProcEntry, SizeOf(TProcessEntry32), 0); ProcEntry.dwSize := SizeOf(TProcessEntry32); if Process32First(SnapHandle, ProcEntry) then begin if ProcEntry.th32ProcessID = iProcessID then begin Result := ProcEntry.cntThreads; Exit; end; while Process32Next(SnapHandle, ProcEntry) = true do begin if ProcEntry.th32ProcessID = iProcessID then begin Result := ProcEntry.cntThreads; Break; end; end; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Caption := inttostr( ThreadCount( GetCurrentProcessId )); end;
