Process Thread Set C# with Example



Process Thread Set C# with Example

 using System;
using System.Linq;
using System.Diagnostics;

namespace CSharpMultiThreading
{
    class MainMethodClass
    {
        static void Main()
        {
			EnumThreadsForPid(9912);
        }
    	
		static void EnumThreadsForPid(int pID)
		{
			Process theProc = null;
			try
			{
				theProc = Process.GetProcessById(pID);
			}
			catch(ArgumentException ex)
			{
				Console.WriteLine(ex.Message);
				return;
			}
			
			// List out stats for each thread in the specified process.
			Console.WriteLine("Here are the threads used by: {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);
			}
		}
	}
}
 

0 Comment's

Comment Form

Submit Comment