-1

CPU 使用率が一定時間を下回った後にのみアプリケーションを開くことを許可する次のコードがあります。ただし、CPU 使用率の急上昇を回避できるように、使用率が少なくとも 5 秒間このように低く保たれるようにする何かを追加するための助けが必要です。

cpuUsage = new PerformanceCounter("Processor", "% Processor Time", "_Total");
var usage = cpuUsage.NextValue();
do
{
    Thread.Sleep(TimeSpan.FromSeconds(1));
    usage = cpuUsage.NextValue();
    Console.WriteLine(usage + "%");
} while (usage > 10.00);

Process proc = new Process();
proc.StartInfo = new ProcessStartInfo(@"C:\Documents and Settings\rcgames\Desktop\Game1.exe");
proc.Start();
4

1 に答える 1

1
int secondsWhileLowUsage = 0;     
do {
    cpuUsage = new PerformanceCounter("Processor", "% Processor Time", "_Total");
    var usage = cpuUsage.NextValue();
    do
    {
        Thread.Sleep(TimeSpan.FromSeconds(1));
        usage = cpuUsage.NextValue();
        if (usage > 10.00)
            secondsWhileLowUsage = 0;

        Console.WriteLine(usage + "%");
    } while (usage > 10.00);
    secondsWhileLowUsage ++; 
} while (secondsWhileLowUsage < 5)

Process proc = new Process();
proc.StartInfo = new ProcessStartInfo(@"C:\Documents and Settings\rcgames\Desktop\Game1.exe");
proc.Start();
于 2013-08-05T15:31:44.037 に答える