初始化
This commit is contained in:
21
CommonTools/CPUData.cs
Normal file
21
CommonTools/CPUData.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user