Files
Web_BLSKafka_Server_Prod/CommonTools/CPUData.cs

22 lines
627 B
C#
Raw Normal View History

2025-11-21 08:48:01 +08:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CommonTools
{
public class CPUData
{
public static double GetCPU()
{
PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
cpuCounter.NextValue(); // 初始化计数器,让它开始计数
System.Threading.Thread.Sleep(1000); // 等待一秒
double cpuUsage = cpuCounter.NextValue(); // 获取CPU使用率
return cpuUsage;
}
}
}