CPU内存占用

jxq789478 2010-08-30 11:38:24
请问大家,如何用C#实现点击一个按钮后,把当前系统各个进程,CPU及内存使用情况输出到一个LISTBOX中;就像任务管理器一样?
...全文
379 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
云瑀 2010-08-30
  • 打赏
  • 举报
回复
PerformanceCounter cpuCounter; 
PerformanceCounter ramCounter;

cpuCounter = new PerformanceCounter();

cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";

ramCounter = new PerformanceCounter("Memory", "Available MBytes");


public string getCurrentCpuUsage(){
cpuCounter.NextValue()+"%";
}

public string getAvailableRAM(){
ramCounter.NextValue()+"MB";
}

flowerjack 2010-08-30
  • 打赏
  • 举报
回复
porschev 2010-08-30
  • 打赏
  • 举报
回复
帮顶。。。。。。
huwei12345 2010-08-30
  • 打赏
  • 举报
回复
在 process 里面找找相关方法
捷哥1999 2010-08-30
  • 打赏
  • 举报
回复
参考:
How to get CPU usage by performance counters (without PDH)
http://www.codeproject.com/KB/system/cpuusageByDudiAvramov.aspx
Get CPU Usage with GetSystemTimes
http://www.codeproject.com/KB/threads/Get_CPU_Usage.aspx
Getting CPU Usage in a Multiprocessor Machine
http://www.codeproject.com/KB/system/MultiCPUUsage.aspx
bbb332 2010-08-30
  • 打赏
  • 举报
回复
学习了呀
wuyq11 2010-08-30
  • 打赏
  • 举报
回复
PerformanceCounter cpuCounter;
PerformanceCounter ramCounter;
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
public string getCurrentCpuUsage(){
cpuCounter.NextValue()+"%";
}

public string getAvailableRAM(){
ramCounter.NextValue()+"MB";
}
http://www.codeproject.com/KB/system/processescpuusage.aspx
jxq789478 2010-08-30
  • 打赏
  • 举报
回复
为什么我用ramCounter = new PerformanceCounter("Memory", "Available MBytes");
取到的每个进程的内存值都是一样的啊?
s8975565 2010-08-30
  • 打赏
  • 举报
回复

listBox1.Items.Clear();
Process[] ps = Process.GetProcesses();
for (int i = 0; i < ps.Length; i++)
{
this.listBox1.Items.Add(ps[i].ProcessName + "------>" + ps[i].Id);
}
this.listBox1.SelectedIndex = indexForUser;
lblProcess.Text = "进程数:" + ps.Length;

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧