实现效果:
知识运用:
Process类的GetProcesses方法
public static Process[] GetProcesses() //为本地计算机上的每个进程资源创建一个新的Process组件
public static Process[] GetProcesses(string machineName) //为指定计算机
Process类的一些属性
public string ProcessName { get; } //获取进程名称
public int Id { get; } //获取进程ID
public ProcessThreadConllection Threads { get; } //获取在关联进程中运行的一组线程
public int BasePriority { get ;} //获取管理进程的基本优先级
public int WorkingSet { get;} //获取关联进程的物理内春总量 (单位字节)
public int VirtualMemorySize {get;} //获取虚拟内存大小
实现代码:
private void button1_Click(object sender, EventArgs e) { try { listView1.Items.Clear(); Process[] myProcess = Process.GetProcesses(textBox1.Text); string[] Minfo=new string[6]; foreach(Process pro in myProcess) { Minfo[0] = pro.ProcessName; Minfo[1] = pro.Id.ToString(); Minfo[2] = pro.Threads.Count.ToString(); Minfo[3] = pro.BasePriority.ToString(); Minfo[4] = (pro.WorkingSet/1024)+"K"; Minfo[5] = (pro.VirtualMemorySize / 1024) + "k"; ListViewItem item = new ListViewItem(Minfo); listView1.Items.Add(item); } } catch (Exception) { MessageBox.Show("远程计算机连接失败"); }