Click here to Skip to main content
15,919,132 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi, thank you for your attention, first.

Now, I need to get an exact CPU usage of certain process.

I googled all day long looking for this stuff

and I got this codes.

while (true)
using (PerformanceCounter pcProcess = new PerformanceCounter("Process", "% Processor Time", _testProcess.ProcessName))
Console.WriteLine("Process:{0} CPU% {1}", _testProcess.ProcessName, pcProcess.NextValue());

It gives some value but unfortunately it is little bigger than it is supposed to be when it is compared to the one in the Task Manager.

When I try to get the entire CPU usage with the same way, it seems to be right

but I can't figure out why it is so much bigger than it should be.

Sometimes it is bigger than the entire CPU usage.

I need some help over here.

If I can, I want to give someone who solves this problem something.

Thanks and regards.

Updated 28-Jan-10 21:49pm

1 solution


You definitely need to look at this article:
How to get CPU usage of processes and threads[^]

There are number of technics described. I'm pretty sure if you'll use win32api, you'll get exactly what you need.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900