Required to create an analog Task Manager. Use of cp processes is tracked using PerformanceCounter. I found an example on the microsoft site and tried to adapt with my class to encapsulate process properties and CPU data in one object.

class MyProcess : IDisposable { private Process process { get; set; } private PerformanceCounter performance; ... public float CPUusage { get { return performance.NextValue(); } } public MyProcess(Process process) { this.process = process; performance = new PerformanceCounter("Process", "% Processor Time", process.ProcessName, true); } public void Dispose() { performance.Dispose(); } } 

When displaying noticed that sumarno used more than 100%. Also, when closing one of the processes, my property (CPUusage) throws an exception that I cannot catch in the code. enter image description here The listing code is overloaded for the sake of tabular style, in fact it is indistinguishable from that in the example.

Help to understand how to get the CPU load by a specific process.

    1 answer 1

    Because counter \Process(…)\% Processor Time shows N * 100 load, where N is the number of processor cores, to use the average load on all cores you need to use the counter \Processor(…)\% Processor Time :

    Read more here .