22 lines
627 B
C#
22 lines
627 B
C#
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;
|
|
}
|
|
}
|
|
}
|