I have this code that runs through all threads. I would like to get the threads only from my own process, without having to loop through all the threads running on the system.
var
SnapProcHandle: THandle;
NextProc : Boolean;
TThreadEntry : TThreadEntry32;
begin
SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
Result := (SnapProcHandle <> INVALID_HANDLE_VALUE);
if Result then
try
TThreadEntry.dwSize := SizeOf(TThreadEntry);
NextProc := Thread32First(SnapProcHandle, TThreadEntry);
while NextProc do
begin
if TThreadEntry.th32OwnerProcessID = PID then
begin
Memo1.Lines.Add('Thread ID '+IntToStr(TThreadEntry.th32ThreadID));
Memo1.Lines.Add('base priority '+inttostr(TThreadEntry.tpBasePri));
Memo1.Lines.Add('delta priority '+inttostr(TThreadEntry.tpBasePri));
end;
NextProc := Thread32Next(SnapProcHandle, TThreadEntry);
end;
finally
CloseHandle(SnapProcHandle);
end;
end;