C#遍歷體系過程的辦法。本站提示廣大學習愛好者:(C#遍歷體系過程的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#遍歷體系過程的辦法正文
本文實例講述了C#遍歷體系過程的辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:
樹立一個listBox將過程稱號遍歷出來
this.listBox1.Items.Clear(); Process[] MyProcesses=Process.GetProcesses(); foreach(Process MyProcess in MyProcesses) { this.listBox1.Items.Add(MyProcess.ProcessName); } this.listBox1.SelectedIndex=0;
選中listBox外面的項後將過程具體信息顯示在左面的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="線程優先級:"+MyProcess[0].PriorityClass.ToString(); this.label6.Text="啟動時光:"+MyProcess[0].StartTime.ToLongTimeString(); this.label7.Text="公用內存:"+(MyProcess[0].PrivateMemorySize/1024).ToString()+"K"; this.label8.Text="峰值虛擬內存:"+(MyProcess[0].PeakVirtualMemorySize/1024).ToString()+"K"; this.label9.Text="峰值分頁內存:"+(MyProcess[0].PeakPagedMemorySize/1024).ToString()+"K"; this.label10.Text="分頁體系內存:"+(MyProcess[0].PagedSystemMemorySize/1024).ToString()+"K"; this.label11.Text="分頁內存:"+(MyProcess[0].PagedMemorySize/1024).ToString()+"K"; this.label12.Text="未分頁體系內存:"+(MyProcess[0].NonpagedSystemMemorySize/1024).ToString()+"K"; this.label13.Text="物理內存:"+(MyProcess[0].WorkingSet/1024).ToString()+"K"; this.label14.Text="虛擬內存:"+(MyProcess[0].VirtualMemorySize/1024).ToString()+"K"; } catch(Exception Err) { MessageBox.Show("沒有此過程,沒法獲得信息!","信息提醒",MessageBoxButtons.OK,MessageBoxIcon.Information); //不處置異常 }
願望本文所述對年夜家的C#法式設計有所贊助。