获取电脑cpu的使用情况

using System;
using System.Diagnostics;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            PerformanceCounter[] counters = new PerformanceCounter[System.Environment.ProcessorCount];
            for (int i = 0; i < counters.Length; i++)
            {
                counters[i] = new PerformanceCounter("Processor", "% Processor Time", i.ToString());
            }

            while (true)
            {
                for (int i = 0; i < counters.Length; i++)
                {
                    float f = counters[i].NextValue();
                    Console.WriteLine("CPU-{0}: {1:f}%", i, f);
                }
                Console.WriteLine();
                System.Threading.Thread.Sleep(1000);
            }
        }
    }
}

http://www.cnblogs.com/kevinGao/archive/2011/12/09/2671025.html

http://www.cnblogs.com/shuncy/archive/2008/11/07/1328738.html

posted @ 2015-10-13 09:15  lwn6  阅读(208)  评论(0编辑  收藏  举报
什么是幸福?天天在做自己想做的事情,家人、同事、朋友、客户、网友都和和睦睦,身体健康、钱包鼓鼓、女朋友天天开心、生活无忧无虑就是最大的幸福