Calculate CPU usage for a Windows process?

冷暖自知 提交于 2019-12-19 04:14:54

问题


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

I have tried using PerformanceCounter as described in 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:


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.



来源:https://stackoverflow.com/questions/1364801/calculate-cpu-usage-for-a-windows-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!