In fact, Process \% Processor Time \ Instance counter returns% of the time that the monitored process uses for% User time for one processor. Thus, the limit is 100% * the number of processors that you have.
There seems to be no easy way to calculate the value that taskmgr displays using perfmon counters. See this link .
Also remember that the percentage of CPU usage is not a fixed value, but a calculated value:
((total processor time at time T2) - (total processor time at time T1) / (T2 - T1))
This means that the values depend on T2 and T1, so there may be differences between what you see in the task manager and what you calculate if T2 and T1 used by the task manager are slightly different from T2 and T1 used by your program.
If you are interested, I can provide you with code to retrieve this value using P / Invoke. But you will lose the benefits of performance counters (for example, monitoring remote processes).
ken2k
source share