How can I get CPU Load per core (quadcore cpu), in C#?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can either use WMI or the System.Diagnostics namespace. From there you can grab any of the performance counters you wish (however it takes a second (1-1.5s) to initialize those – reading values is ok, only initialization is slow)
Code can look then like this:
Important thing is that you cant rely on native .net calculation for 100nsInverse performance counters (returns only 0 or 100 for me … bug?) but you have to calculate it yourself and for that you need an archive of last CounterSamples for each instance (instances represent a core or a sum of those cores).
There appears to be a naming convetion for those instances :
0,0 – first cpu first core
0,1 – first cpu second core
0,_Total – total load of first cpu
_Total – total load of all cpus
(not verified – would not recommend to rely on it untill further investigation is done)…