Getting CPU usage of a process in C#

前端 未结 2 569
臣服心动
臣服心动 2021-02-01 10:15

I would like to get CPU usage for a specific process..

This code

total_cpu = new PerformanceCounter(\"Processor\", \"% Processor Time\", \"_Total\");
         


        
2条回答
  •  情书的邮戳
    2021-02-01 10:56

    Dividing by the processor/core count is what seemed to yield fairly accurate results when comparing against Task Manager.

    To save people time:

    // This will return the process usage as a percent of total processor utilisation.
    var processUsage = process_cpu_usage/nextValue() / Environment.ProcessorCount;
    

提交回复
热议问题