C#如何从应用程序PID获得CPU负载 [英] C# How do I get CPU load from application PID
问题描述
问候:)
我有一个名为Test.exe的应用程序。在这个应用程序中,我可以立即获得自己的名称和进程ID,如下所示:
string processName = Process.GetCurrentProcess()。ProcessName;
int processID = Process.GetCurrentProcess()。Id;
使用性能计数器,在Test.exe中,我可以得到CPU使用应用程序名称加载自身。
现在说点。 我运行了10个Test.exe实例。每个操作系统都有自己独立的PID或进程标识号。我需要让Test.exe的每个应用程序对其自己的CPU负载进行采样。因此,我必须通过PID 检测CPU负载,因为有相同应用程序的10个实例在运行。
任何指针或样品都非常感激。 :)
Greetings :)
I have an application named Test.exe. Inside this application I can immediately get its own name and process ID like this:
string processName = Process.GetCurrentProcess().ProcessName;
int processID = Process.GetCurrentProcess().Id;
Using performance counters, inside Test.exe, I can get the CPU load of itself using the application name.
Now for the point. I run 10 instances of Test.exe. Each one has its own separate PID or process Identification Number assigned to it by the OS. I need to let each application of Test.exe sample it's own CPU load. Therefore I have to detect CPU load via the PID since there are 10 instances of the same application running.
Any pointers or samples much appreciated. :)
推荐答案
看看这个 [ ^ ]回答。据我所知,它可以帮助您找到正确的过程和相应的计数器实例。
Have a look at this[^] answer. As far as I can see, it would help you to locate the correct process and corresponding counter instance.
这篇关于C#如何从应用程序PID获得CPU负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!