Question

I'm currently doing this:

PerformanceCounter cpuUsage = new PerformanceCounter("Processor", "% Processor Time", "_Total");
cpuUsage.NextValue();
System.Threading.Thread.Sleep(1000);
RV = cpuUsage.NextValue();

I call the function periodically to get CPU usage. When I monitor the system in TaskManager, the CPU usage reported by PerformanceCounter is consistently 15-20% higher than what TaskManager reports (30% in TaskManager = 50% from PerformanceCounter).

Maybe there's documentation that I overlooked, but does anyone have an explanation? Maybe the CPU usage at the instant it checks is higher and task manager reports an average?

Was it helpful?

Solution

  new PerformanceCounter("Processor", ...);

You are using the wrong counter if you insist on seeing an exact match with Task Manager or Perfmon. Use "Processor Information" instead of "Processor". The reason these counters show different values is addressed pretty well in this blog post. Which counter is "right" is a question I wouldn't want to touch with a ten-foot pole :)

OTHER TIPS

Did not have luck with accepted answer, so adding my comment as an answer to hopefully help people find this through online search a little better.

var counter = new PerformanceCounter("Processor Information", "% Processor Utility", "_Total");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top