Using system;using system.collections.generic;using system.linq;using system.text;using System.Diagnostics; Namespace consoleapp{ class processdo { /<summary> &NB Sp //Get process-related information //</summary> public static void G Etprocessinfomation () { Process Pro = Process.getproce Ssesbyname ("QQ") [0]; Console.WriteLine ("Process name:" + Pro.) ProcessName); Console.WriteLine ("Process ID:" + Pro.) Id.tostring ()); Console.WriteLine ("Start time:" + Pro. Starttime.tolongdatestring () + Pro. Starttime.tolongtimestring ()); Console.WriteLine ("Response:" + Pro.) Responding.tostring ()); Console.WriteLine ("Associated Process handle:" + Pro.) Handle.toString ()); Console.WriteLine ("The number of handles opened by the process:" + Pro.) Handlecount.tostring ()); Console.WriteLine ("Main Window handle:" + Pro. Mainwindowhandle.tostring ()); Console.WriteLine ("main window title:" + Pro. MainWindowTitle); Console.WriteLine ("Number of modules:" + Pro. Modules.Count.ToString ()); Console.WriteLine ("Base priority:" + Pro.) Basepriority.tostring ()); Console.WriteLine ("Promotion priority:" + Pro. Priorityboostenabled.tostring ()); Console.WriteLine ("Processor:" + Pro. Processoraffinity.toint32 (). ToString ()); Console.WriteLine ("Minimum Working set:" + Pro. Minworkingset.toint32 (). ToString ()); Console.WriteLine ("Max Working set:" + Pro.) Maxworkingset.toint32 (). ToString ()); Console. WriteLine ("Working set:" + Pro.) Workingset.tostring ()); Console.WriteLine ("Peak Working set:" + Pro. Peakworkingset.tostring ()); Console.WriteLine ("Dedicated Memory size:" + Pro. Privatememorysize.tostring ()); Console.WriteLine ("Nonpaged Memory Size:" + Pro.) Nonpagedsystemmemorysize.tostring ()); Console.WriteLine ("Paging Memory Size:" + Pro. Pagedmemorysize.tostring ()); Console.WriteLine ("Peak Paging memory Size:" + Pro. Peakpagedmemorysize.tostring ()); Console.WriteLine ("Virtual Memory Size:" + Pro. Virtualmemorysize.tostring ()); Console.WriteLine ("Peak Virtual memory Size:" + Pro. Peakvirtualmemorysize.tostring ()); Console.WriteLine ("Occupy Time:" + Pro.) Totalprocessortime.tostring ()); Console.WriteLine ("Privilege Time:" + Pro. PrivilegedprocessoRtime.tostring ()); Console.WriteLine ("User occupied time:" + Pro.) Userprocessortime.tostring ()); } //< summary> //process thread details //</summary> & nbsp public static void Getprocessthreadinfomation () { Proc ESS Pro = Process.getprocessesbyname ("QQ") [0]; Console.WriteLine (" The thread details for the QQ program process are as follows: "); int length = Pro. threads.count; for (int i = 0; i < length; i++) &NB Sp { var thread = Pro. threads[i]; Console.WriteLine ("identifier:" + Thread.) Id.tostring ()); Console.WriteLine ("Base priority:" + thread.) Basepriority.tostring ()); Console.WriteLine ("Current priority:" + thread.) Currentpriority.tostring ()); Console.WriteLine ("Memory Address:" + Thread. Startaddress.toint32 ()); Console.WriteLine ("Start time:" + thread.) Starttime.tostring ()); Console.WriteLine ("Use time:" + thread.) Userprocessortime.tostring ()); Console.Write ("Current status:"); & nbsp switch (thread. ThreadState) { &NBS P Case threadstate.initialized: &N Bsp Console.WriteLine ("Thread has been initialized but not started"); break; &NB Sp Case threadstate.ready: & nbsp Console.WriteLine ("Thread ready to run on next available processor"); &NBSP ; break; Case threadstate.running: Console.WriteLine ("Processors currently in use"); break; &NBS P Case threadstate.standby: Consol E.writeline ("Thread will use processor"); break; &NBSp case threadstate.terminated: &NB Sp Console.WriteLine ("Thread completed and exited"); break; Case Threa dstate.transition: Console.WriteLine ("Line The process can execute money waiting outside the processor resources "); break;   ; case threadstate.unknown: Console.WriteLine ("Status Unknown"); &NBS P break; Case THREADSTATE.W ait:   Console.WriteLine ("Waiting for peripheral operations to complete or resource release"); break; &NB Sp default: BREAK;&NB Sp } if (thread. ThreadState = = threadstate.wait) { Console.Write ("Wait Reason:"); switch (thread. Waitreason) { &NBSP ; case threadwaitreason.eventpairhigh:   Console.WriteLine ("Thread is waiting for event to High"); break; &NB Sp case threadwaitreason.eventpairlow: &NB Sp Console.WriteLine ("Thread is waiting for event to Low"); break; &NB Sp Case threadwaitreason.executiondelay: & nbsp Console.WriteLine ("Thread Execution delay"); &NB Sp break; Case Threadwaitreason.executive: Console.WriteLine ("Thread is waiting for scheduler"); &NBSP ; break; Case Threadwaitreason.fre epage: Console.WriteLine ( "Thread is waiting for available virtual memory pages"); break; Case threadwaitreason.lpcreceive:  ; Console.WriteLine ("Thread is waiting for local procedure call Arrival "); break; &NBSP; case threadwaitreason.lpcreply: Console.WriteLine ("Thread is waiting for reply to local procedure call arrives"); &NBS P break; &NBS P case threadwaitreason.pagein: &N Bsp Console.WriteLine ("Thread is waiting for virtual memory page to reach Memory"); & nbsp break; &NBS P Case threadwaitreason.pageout: () nbsp Console.WriteLine ("Thread is waiting for virtual memory page to write to disk"); &NBSP; break; Case Thread waitreason.suspended: Con Sole. WriteLine ("Thread execution pause"); Brea k; Case Threadwaitreason.systemallocati on: Console.WriteLine ("Threading Waiting for system to be assigned "); break; Case threadwaitreason.unknown: & nbsp Console.WriteLine ("Threads Wait for location reasons"); &NBSp break; &NBS P case threadwaitreason.userrequest: &NBS P Console.WriteLine ("Threads are waiting for user requests"); break; &NB Sp Case threadwaitreason.virtualmemory: &N Bsp Console.WriteLine ("Thread is waiting for system to allocate virtual memory"); &N Bsp break; DEFA ult: break; } } & nbsp Console.WriteLine (); } &nbs P } //<summary> //Limited application run time &NBSP ; //that the Affiliate program runs out of Setup will automatically close //</summary> Public stat IC void Getkillappforwaittime () { Process proc = new P Rocess (); Proc. StartInfo = new ProcessStartInfo (@ "C:\Documents and settings\zkk\ Desktop \mysql_20120925.sql"); & nbsp //Start Application Proc. Start (); /wait for the program to be completed loading Proc. WaitForInputIdle (); &NBsp //wait for program end execution Proc. WaitForExit; //If the program is closed before the time limit, hasexited will be true if (proc. HasExited = = false) { //test Whether the program has stopped responding if (proc. Responding) { &NBSP ; //program has a response to close the main view Proc. CloseMainWindow (); } &NBSP ; else { &NBSP ; //If the program does not respond, it will be forced to close &NBSp Proc. Kill (); } } & nbsp } }}
C # Gets information about a process or thread