views:

537

answers:

1

Given a process ID, how can i get the cpu load from this process with C#?

I have tried using PerformanceCounter as described in http://stackoverflow.com/questions/1277556/c-calculate-cpu-usage-for-a-specific-application

I have also tried to manually take two values of the total cpu time for the process within a timeframe and divide the delta-cpu-time with the delta-total-time.

Both these methods seems to work fine at first but if i put my application next to windows task manager my application always shows about twice as much as the task manager does. I have tried to update with various timesteps from 10ms to 10sec and get same result all the time.

Hmm, realized when i wrote this that it might be some kind of dual core issue...

+1  A: 

If you have two cores, the task manager is going to report 100% usage of 1 CPU as 50%. That's probably your issue right there.

Mark P Neyer