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"
积跬步,至千里!
本文来自博客园,作者:LI小白,转载请注明原文链接:https://www.cnblogs.com/LittleBai/p/17595963.html