列出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); // 不处理异常 }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值