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

发布时间 2023-08-01 11:13:30作者: LI小白
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());
            }
        }

    }
}

 积跬步,至千里!