显示系统进程信息

  1using System;
  2using System.Drawing;
  3using System.Collections;
  4using System.ComponentModel;
  5using System.Windows.Forms;
  6using System.Data;
  7// 添加新的命名空间。
  8using System.Diagnostics;
  9
 10namespace ListApp
 11{
 12    /// <summary>
 13    /// 显示系统进程信息。
 14    /// </summary>

 15    public class Form1 : System.Windows.Forms.Form
 16    {
 17        private System.Windows.Forms.Button button1;
 18        private System.Windows.Forms.ListView listView1;
 19        /// <summary>
 20        /// 必需的设计器变量。
 21        /// </summary>

 22        private System.ComponentModel.Container components = null;
 23
 24        public Form1()
 25        {
 26            //
 27            // Windows 窗体设计器支持所必需的
 28            //
 29            InitializeComponent();
 30
 31            //
 32            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
 33            //
 34        }

 35
 36        /// <summary>
 37        /// 清理所有正在使用的资源。
 38        /// </summary>

 39        protected override void Dispose( bool disposing )
 40        {
 41            if( disposing )
 42            {
 43                if (components != null
 44                {
 45                    components.Dispose();
 46                }

 47            }

 48            base.Dispose( disposing );
 49        }

 50
 51        Windows Form Designer generated code
 96
 97        /// <summary>
 98        /// 应用程序的主入口点。
 99        /// </summary>

100        [STAThread]
101        static void Main() 
102        {
103            Application.Run(new Form1());
104        }

105        // 显示系统中的进程信息。
106        private void button1_Click(object sender, System.EventArgs e)
107        {
108            Process[] p = Process.GetProcesses();
109            listView1.Clear();
110            listView1.Columns.Add("进程ID号"100, HorizontalAlignment.Left);
111            listView1.Columns.Add("进程名称"100, HorizontalAlignment.Left);
112            listView1.Columns.Add("进程优先级"100, HorizontalAlignment.Left);
113            listView1.Columns.Add("虚拟内存"100, HorizontalAlignment.Left);
114            listView1.Columns.Add("物理内存"100, HorizontalAlignment.Left);
115            listView1.Columns.Add("总的处理器时间"100, HorizontalAlignment.Left);
116            listView1.Columns.Add("用户处理器时间"100, HorizontalAlignment.Left);
117            listView1.Columns.Add("启动时间"100, HorizontalAlignment.Left);
118            foreach(Process i in p)
119            {
120                string[] str =
121                    {
122                        i.Id.ToString(),
123                        i.ProcessName,
124                        i.BasePriority.ToString(),
125                        i.VirtualMemorySize.ToString(),
126                        i.WorkingSet.ToString(),
127                        i.TotalProcessorTime.ToString(),
128                        i.UserProcessorTime.ToString(),
129                        i.StartTime.ToString()
130                    }
;
131                ListViewItem n = new ListViewItem(str);
132                listView1.Items.Add(n);
133            }

134        }

135    }

136}

137
posted on 2007-08-24 09:51  Gofficer  阅读(322)  评论(0)    收藏  举报