Process.GetProcessById : Process « System.Diagnostics « C# / C Sharp by API






Process.GetProcessById

 

using System;
using System.Diagnostics;

class MainClass
{
  public static void EnumThreadsForPid(int pID)
  {
    Process theProc;

    try {
      theProc = Process.GetProcessById(pID);
    } catch {
      Console.WriteLine("-> Sorry...bad PID!");
      return;
    }
    
    Console.WriteLine("Here are the thread IDs for: {0}", theProc.ProcessName);

    ProcessThreadCollection theThreads = theProc.Threads;
    foreach(ProcessThread pt in theThreads)
    {
      string info = string.Format("-> Thread ID: {0}\tStart Time {1}\tPriority {2}", pt.Id , pt.StartTime.ToShortTimeString(), pt.PriorityLevel);
      Console.WriteLine(info);
    }
  }

  static void Main(string[] args)
  {
    int theProcID = 10001;
    EnumThreadsForPid(theProcID);
  }
}

   
  








Related examples in the same category

1.Process.CloseMainWindow
2.Process.Exited
3.Process.GetCurrentProcess()
4.Process.Kill()
5.Process.Modules
6.Process.PeakWorkingSet64
7.Process.PriorityClass
8.Process.PrivateMemorySize
9.Process.ProcessName
10.Process.StandardOutput.ReadToEnd()
11.Process.Start
12.Process.StartInfo.RedirectStandardOutput
13.Process.Threads
14.Process.TotalProcessorTime
15.Process.VirtualMemorySize
16.Process.WaitForExit
17.Process.WorkingSet