How do you detect the number of physical processors/cores in .net?
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.
returns the number of logical processors
For physical processor count you’d probably need to use WMI – the following metadata is supported in XP/Win2k3 upwards (Functionality enabled in SP’s prior to Vista/Win2k8).
Be cautious that HyperThreaded CPUs appear identical to multicore’d CPU’s yet the performance characteristics are very different.
To check for HT-enabled CPUs examine each instance of Win32_Processor and compare these two properties.
On multicore systems these are typically the same the value.
Also, be aware of systems that may have multiple Processor Groups, which is often seen on computers with a large number of processors. By default .Net will only using the first processor group – which means that by default, threads will utilize only CPUs from the first processor group, and
Environment.ProcessorCountwill return only the number of CPUs in this group. According to Alastair Maw’s answer, this behavior can be changed by altering the app.config as follows: