G
Guest
I'm trying to write a c# class that will outprint the cpu use to the console
(console.writeline). I basically copied the msdn supplied code, but what
prints out is either 0%, 100%, or 51.02...%, every time. If I make a GUI for
the app, it displays the correct % in the GUI display, and the debug console
- but the console app never displays the right %. Any ideas? This is the msdn
example - all I added to mine was the outprint to the console.
<code>
private static PerformanceCounter _cpuCounter;
private static float CpuUsage
{
get
{
if (_cpuCounter == null)
{
_cpuCounter = new PerformanceCounter(
"Processor", "% Processor Time", "_Total", true);
}
return _cpuCounter.NextValue();
}
}
</code
(console.writeline). I basically copied the msdn supplied code, but what
prints out is either 0%, 100%, or 51.02...%, every time. If I make a GUI for
the app, it displays the correct % in the GUI display, and the debug console
- but the console app never displays the right %. Any ideas? This is the msdn
example - all I added to mine was the outprint to the console.
<code>
private static PerformanceCounter _cpuCounter;
private static float CpuUsage
{
get
{
if (_cpuCounter == null)
{
_cpuCounter = new PerformanceCounter(
"Processor", "% Processor Time", "_Total", true);
}
return _cpuCounter.NextValue();
}
}
</code