Enumerate over threads in a given PID : Process : Development C# Examples


C# Examples » Development » Process »

 

Enumerate over threads in a given PID









    
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);
    }
}
    
   
  
   



Output

-> Sorry...bad PID!


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» Process