初始化CRICS

This commit is contained in:
2025-12-11 09:17:16 +08:00
commit 83247ec0a2
2735 changed files with 787765 additions and 0 deletions

34
Common/CPUData.cs Normal file
View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Common
{
public class CPUData
{
public static PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
public static double GetCPU()
{
cpuCounter.NextValue(); // 初始化计数器,让它开始计数
System.Threading.Thread.Sleep(1000); // 等待一秒
double cpuUsage = cpuCounter.NextValue(); // 获取CPU使用率
return cpuUsage;
}
[DllImport("kernel32.dll")]
private static extern void GetSystemTimePreciseAsFileTime(out long fileTime);
// 将 FILETIME (long) 转换为 DateTime
public static DateTime GetNowPrecise()
{
long fileTime;
GetSystemTimePreciseAsFileTime(out fileTime);
DateTime localTime = DateTime.FromFileTimeUtc(fileTime).ToLocalTime();
return localTime;
}
}
}