C#遍歷系統(tǒng)進程的方法
更新時間:2015年05月14日 10:08:37 作者:歐陽不瘋
這篇文章主要介紹了C#遍歷系統(tǒng)進程的方法,涉及C#底層操作獲取系統(tǒng)信息與硬件信息的相關(guān)技巧,需要的朋友可以參考下
本文實例講述了C#遍歷系統(tǒng)進程的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
建立一個listBox將進程名稱遍歷進去
this.listBox1.Items.Clear(); Process[] MyProcesses=Process.GetProcesses(); foreach(Process MyProcess in MyProcesses) { this.listBox1.Items.Add(MyProcess.ProcessName); } this.listBox1.SelectedIndex=0;
選中l(wèi)istBox里面的項后將進程詳細信息顯示在右面的Label中
try { string ProcessName=this.listBox1.Text; this.groupBox1.Text=ProcessName+"進程的詳細信息"; Process[] MyProcess=Process.GetProcessesByName(ProcessName); this.label1.Text="進程影象名:"+MyProcess[0].ProcessName; this.label2.Text="進程ID:"+MyProcess[0].Id; this.label3.Text="啟動線程樹:"+MyProcess[0].Threads.Count.ToString(); this.label4.Text="CPU占用時間:"+MyProcess[0].TotalProcessorTime.ToString(); this.label5.Text="線程優(yōu)先級:"+MyProcess[0].PriorityClass.ToString(); this.label6.Text="啟動時間:"+MyProcess[0].StartTime.ToLongTimeString(); this.label7.Text="專用內(nèi)存:"+(MyProcess[0].PrivateMemorySize/1024).ToString()+"K"; this.label8.Text="峰值虛擬內(nèi)存:"+(MyProcess[0].PeakVirtualMemorySize/1024).ToString()+"K"; this.label9.Text="峰值分頁內(nèi)存:"+(MyProcess[0].PeakPagedMemorySize/1024).ToString()+"K"; this.label10.Text="分頁系統(tǒng)內(nèi)存:"+(MyProcess[0].PagedSystemMemorySize/1024).ToString()+"K"; this.label11.Text="分頁內(nèi)存:"+(MyProcess[0].PagedMemorySize/1024).ToString()+"K"; this.label12.Text="未分頁系統(tǒng)內(nèi)存:"+(MyProcess[0].NonpagedSystemMemorySize/1024).ToString()+"K"; this.label13.Text="物理內(nèi)存:"+(MyProcess[0].WorkingSet/1024).ToString()+"K"; this.label14.Text="虛擬內(nèi)存:"+(MyProcess[0].VirtualMemorySize/1024).ToString()+"K"; } catch(Exception Err) { MessageBox.Show("沒有此進程,無法獲取信息!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information); //不處理異常 }
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
C#中ManualResetEvent實現(xiàn)線程的暫停與恢復(fù)
本文主要介紹了C#中ManualResetEvent實現(xiàn)線程的暫停與恢復(fù),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-01-01