Csharp/C Sharp by API/System.Diagnostics/ProcessThread — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:31, 26 мая 2010

ProcessThread.BasePriority

 
using System;
using System.Diagnostics;
class MainClass
{
   public static void Main()
   {
      Process thisProc = Process.GetCurrentProcess();
      ProcessThreadCollection myThreads = thisProc.Threads;
      foreach(ProcessThread pt in myThreads)
      {
         Console.WriteLine("thread:  {0}", pt.Id);
         Console.WriteLine("    started: {0}", pt.StartTime);
         Console.WriteLine("    CPU time: {0}", pt.TotalProcessorTime);
         Console.WriteLine("    priority: {0}", pt.BasePriority);
         Console.WriteLine("    thread state: {0}", pt.ThreadState); 
      }
   }
}


ProcessThread.StartTime

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


ProcessThread.ThreadState

 

using System;
using System.Diagnostics;
class MainClass
{
   public static void Main()
   {
      Process thisProc = Process.GetCurrentProcess();
      ProcessThreadCollection myThreads = thisProc.Threads;
      foreach(ProcessThread pt in myThreads)
      {
         Console.WriteLine("thread:  {0}", pt.Id);
         Console.WriteLine("    started: {0}", pt.StartTime);
         Console.WriteLine("    CPU time: {0}", pt.TotalProcessorTime);
         Console.WriteLine("    priority: {0}", pt.BasePriority);
         Console.WriteLine("    thread state: {0}", pt.ThreadState); 
      }
   }
}


ProcessThread.TotalProcessorTime

 
using System;
using System.Diagnostics;
class MainClass
{
   public static void Main()
   {
      Process thisProc = Process.GetCurrentProcess();
      ProcessThreadCollection myThreads = thisProc.Threads;
      foreach(ProcessThread pt in myThreads)
      {
         Console.WriteLine("thread:  {0}", pt.Id);
         Console.WriteLine("    started: {0}", pt.StartTime);
         Console.WriteLine("    CPU time: {0}", pt.TotalProcessorTime);
         Console.WriteLine("    priority: {0}", pt.BasePriority);
         Console.WriteLine("    thread state: {0}", pt.ThreadState); 
      }
   }
}