I'm looking for a way to get the total number of actual processor cores, as everything I found (e.g. this) returns the number of cores plus Intel's Hyperthreading technology, i.e. I'm shown 8 cores for my i7 6700K, while the processor only has 4 actual cores
. As far as I know, this only applies to Intel processors featuring the Hyperthreading Technology.
Asked
Active
Viewed 964 times
1
-
Possible duplicate of [Is there a way to reliably detect the total number of CPU cores?](http://stackoverflow.com/questions/2575472/is-there-a-way-to-reliably-detect-the-total-number-of-cpu-cores) – Thomas Weller Oct 18 '16 at 12:25
-
Actually it's already in the answer you link to – Thomas Weller Oct 18 '16 at 12:28
-
@ThomasWeller Why would I post if the answer was already given beforehand? – Jan Oct 18 '16 at 12:35
-
Second piece of code in highest voted, accepted answer: `new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get() [...] int.Parse(item["NumberOfCores"].ToString())` – Thomas Weller Oct 18 '16 at 12:37
-
I saw this, but it didn't work out for me (I later found why). Coincidentally, I did some research and stumbled upon akin code, which I transcribed to LINQ, eventually being the same. – Jan Oct 18 '16 at 12:42
-
Thanks to anyone for downvoting this, btw. – Jan Oct 18 '16 at 12:42
1 Answers
2
I figured it out myself (using Linq). Alas, the code is not the fastest in speed terms. Reference System.Management
and you're good to go:
var processorCoreCount = new ManagementObjectSearcher("Select * from Win32_Processor").Get().Cast<ManagementBaseObject>().Sum(item => int.Parse(item["NumberOfCores"].ToString()));

Jan
- 108
- 1
- 7
-
@Picnic8 No, it was not. I posted the solution before ANY comment was published. Besides, he quoted something from an article I (!!!) referenced initially. – Jan Oct 18 '16 at 14:33