C# 获取任务管理器中的CPU使用率

using System;
using System.Diagnostics;
using System.Threading;

namespace CpuUsageTest
{
    internal class Program
    {
        static PerformanceCounter counter = new PerformanceCounter("Processor Information", "% Processor Utility", "_Total");
        static void Main(string[] args)
        {
            counter.NextValue();

            while (true)
            {
                Thread.Sleep(500);
                Console.WriteLine(counter.NextValue());
            }
        }

    }
}

 

cmd 执行命令:

typeperf "\Processor Information(_Total)\% Processor Utility"

 

 积跬步,至千里!

posted @ 2023-08-01 11:07  LI小白  阅读(1491)  评论(0编辑  收藏  举报