导航

ProcessMonitor use C#

Posted on 2005-05-05 22:31  Jworld.net  阅读(320)  评论(0)    收藏  举报
 1private void AddProcess()
 2        {
 3            int a,b;
 4            try
 5            {
 6                prolist=Process.GetProcesses();
 7            }

 8            catch(Exception e)
 9            {
10                MessageBox.Show(e.Message);
11            }

12            for(int i=0;i<prolist.Length;i++)
13            {
14                b=prolist[i].WorkingSet/1024;
15                a=prolist[i].VirtualMemorySize/1024;
16                listView1.Items.Add(new ListViewItem(new string[]{prolist[i].ProcessName,
17                    prolist[i].Id.ToString(),
18                    prolist[i].TotalProcessorTime.ToString(),prolist[i].BasePriority.ToString(),
19                    b.ToString()+"k",a.ToString()+"k"}
));
20            }

21        }

22
23        private void button1_Click(object sender, System.EventArgs e)
24        {
25            for(int i=listView1.SelectedItems.Count-1;i>=0;i--)
26            {
27                ListViewItem li=listView1.SelectedItems[i];
28                for(int j=0;j<prolist.Length;j++)
29                {
30                    if(prolist[j].ProcessName==li.Text)
31                        prolist[j].Kill();
32                }

33                listView1.Items.Remove(li);
34            }

35            

button1 is the method of close process,btw:do not try to close the key process!!!!!
prolist is the process array ,define:

private Process[] prolist=new Process[100];   //LOL