当前位置:编程学习 > C#/ASP.NET >>

CPU内存占用

请问大家,如何用C#实现点击一个按钮后,把当前系统各个进程,CPU及内存使用情况输出到一个LISTBOX中;就像任务管理器一样? --------------------编程问答-------------------- 在 process 里面找找相关方法 --------------------编程问答-------------------- 帮顶。。。。。。 --------------------编程问答-------------------- 参考:http://blog.csdn.net/luols/archive/2010/08/30/5849434.aspx --------------------编程问答-------------------- --------------------编程问答--------------------
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"; 

--------------------编程问答--------------------

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;
--------------------编程问答-------------------- 为什么我用ramCounter = new PerformanceCounter("Memory", "Available MBytes"); 
取到的每个进程的内存值都是一样的啊?
--------------------编程问答-------------------- 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 --------------------编程问答-------------------- 学习了呀 --------------------编程问答-------------------- 参考:
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
--------------------编程问答--------------------
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,