I am curious as to what the .NET property Environment.ProcessorCount
actually returns. Does it return the number of cores, the number of processors or both? If my computer had 2 processors, each with 4 cores, would Environment.ProcessorCount
return 2, 4, or 8?
Asked
Active
Viewed 6,258 times
11

Matthew Scharley
- 127,823
- 52
- 194
- 222

Icemanind
- 47,519
- 50
- 171
- 296
-
2see http://stackoverflow.com/questions/188503/detecting-the-number-of-processors – adrianbanks Nov 22 '09 at 20:15
3 Answers
17
It will return the NUMBER_OF_PROCESSORS environment variable. (see MSDN)
This will equal the number of logical cores - i.e. if you have a HT enabled single core processor, it will return 2.
In your case, it should return 8.
It will be the same number as the number of CPU utilization graphs you will see in task manager.

Marek
- 10,307
- 8
- 70
- 106
-
That is totally false. If you change the environment variable and then start an app from the same environment as the one you change the variable, you will still get the real number of logical processor. As a side note: that is not always true in certain cases which I'm actually looking for - related to hyper threading (Environment.ProcesserCount does not take in account Hyper Threading on one server we have). – Eric Ouellet Jan 14 '15 at 20:43
-
I was quick. I try to undo but I can't. I haven't seen the info in MSDN and in fact is was not there when I checked. But I realized an hour after that it was there for version 4.0 of the framework but your link was probably automatically redirected to 4.5. I can't undo! – Eric Ouellet Jan 14 '15 at 22:05
0
If my computer had 2 processors, each with 4 cores, would Environment.ProcessorCount return 2, 4, or 8?
It returns 8, in my case anyways. (Core i7 860 cpu).

leppie
- 115,091
- 17
- 196
- 297