1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
private void OntimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
int cpuValue = GetCpuValue();
int memValue = GetMemValue();
if (cPgBCPU.InvokeRequired)
{
cPgBCPU.Invoke(new Action(() => cPgBCPU.Value = cpuValue));
}
else
{
cPgBCPU.Value = cpuValue;
}
if (cPgBMem.InvokeRequired)
{
cPgBMem.Invoke(new Action(() => cPgBMem.Value = memValue));
}
else
{
cPgBMem.Value = memValue;
}
// cPgBMem.Value = memValue;
}
private static int GetCpuValue()
{
var CpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
CpuCounter.NextValue();
Thread.Sleep(1000);
int returnValue = (int)CpuCounter.NextValue();
return returnValue;
} |
Partager