手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#遍历系统进程的方法
C#遍历系统进程的方法
摘要:本文实例讲述了C#遍历系统进程的方法。分享给大家供大家参考。具体实现方法如下:建立一个listBox将进程名称遍历进去this.listBo...

本文实例讲述了C#遍历系统进程的方法。分享给大家供大家参考。具体实现方法如下:

建立一个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); //不处理异常 }

希望本文所述对大家的C#程序设计有所帮助。

【C#遍历系统进程的方法】相关文章:

用C#编写获取远程IP,MAC的方法

C#图片压缩的实现方法

C# 格式化字符首字母大写的方法

C# 鼠标穿透窗体功能的实现方法

C#利用com操作excel释放进程的解决方法

c#解压文件的实例方法

C# 获取属性名的方法

重写、隐藏基类(new, override)的方法

C# 设置系统日期格式的方法

c#模拟平抛运动动画的方法详解

精品推荐
分类导航