views:

74

answers:

2

I know I can use System.Environment.ProcessorCount to return the number of "processors" in a machine. What I am trying to do is find out if there is a way to determine the number of cores in the processor, not including hyperthreading as a "core". For example, on a dual core hyperthreading processor, System.Environment.ProcessorCount will return 4 because there are 2 physical cores, both with hyperthreading. What I want to do is return 2 because there are only 2 physical cores.

I am using C#, by the way.

+1  A: 

You can use WMI to obtain the number of cores in the system. This similar question on stack overflow includes a code sample: --> http://stackoverflow.com/questions/1542213/how-to-find-the-number-of-cpu-cores-via-net-c

An important point to keep in mind is that in certain systems this value may not be available; for example, on windows server 2003 you need to download a hotfix from Microsoft to get "NumberOfCores" to work.

Pandincus
+1  A: 

Determining the number of physical CPU's on Windows

Detect Hyperthreading in C# using WMI

Leniel Macaferi
The first link is very helpful, the second is less so (because the first explains that WMI is not reliable).
Steven Sudit