列出C#進程以及詳細資料

來源:互聯網
上載者:User
結合著上一篇,再寫一個擷取進程詳細資料的代碼

建立一個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);
                //不處理異常
            }


http://files.cnblogs.com/mgod/WindowsINI.rar

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.