因此,我正在研究一些在一定比例下检查CPU使用情况的东西,以便它不会让系统停滞不前。我有这样的代码:性能计数器保持cpuUsage在一定的比例下C#
static PerformanceCounter cpuUsage;
public static void Main(string[] args)
{
cpuUsage = new PerformanceCounter("Processor", "% Processor Time", "_Total");
do
{
Console.WriteLine(cpuUsage.NextValue() + " %");
Thread.Sleep(1000);
Console.WriteLine(cpuUsage.NextValue() + " %");
}
while (cpuUsage.NextValue() < 50.00);
}
我最初的想法是用这个做while循环继续检查CPU使用率,直到它去超过50%,则停止循环。但由于某些原因,即使cpuUsage.NextValue大于50,它仍然不会退出循环。我猜这是这个值的问题。有什么建议么?
此外,这些是我的输出:0% 4.6785% 0% 2.34375% 0% 4.6785% 0% 100% 0% 2.345% 任何线索为何总回报一个0之间? – trueamerican420