在 C# 中检索 CPU 使用率
问题:
如何获取整体 CPU C# 的用法应用程序?
答案:
要在 C# 中检索 CPU 使用情况,请使用 PerformanceCounter 类系统.诊断。
实现:
using System.Diagnostics; public class CpuUsage { private static PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); public static float GetCurrentCpuUsage() { return cpuCounter.NextValue(); } }
用法:
float cpuUsage = CpuUsage.GetCurrentCpuUsage(); Console.WriteLine($"Current CPU Usage: {cpuUsage}%");
注意:
以上是如何获取 C# 应用程序中的总体 CPU 使用率?的详细内容。更多信息请关注PHP中文网其他相关文章!