草本枝稼

系统当前进程使用情况
private void button1_Click(object sender, System.EventArgs e)
        {
//获取系统当前所有进程
           this.listBox1.Items.Clear();
            Process[] MyProcesses
=Process.GetProcesses();
           
foreach(Process MyProcess in MyProcesses)
            {
               
this.listBox1.Items.Add(MyProcess.ProcessName);               
            }       
           
this.listBox1.SelectedIndex=0;
        }

       
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
//显示选择的系统进程详细信息
            try
            {
               
string ProcessName=this.listBox1.Text;
               
this.groupBox2.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)
            {
             
//不处理产生的异常
            }
        }

       
private void Form1_Load(object sender, System.EventArgs e)
        {
          button1_Click(
null,null);
        }
       
    }

posted on 2009-08-11 18:04  林声歌  阅读(117)  评论(0编辑  收藏  举报