how to get the number of processors available?

  • Thread starter Thread starter AA
  • Start date Start date
Bad news, EnironmentVariables is a collection and each entry can be modified
So, if you execute this:

System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")

The result in my case is 1

But if you execute

Dim envVars As Collections.IDictionary =
System.Environment.GetEnvironmentVariables()
envVars.Item("NUMBER_OF_PROCESSORS") = 2
System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")

now the result is 2


So, is possible to get the REAL number of processors?

In a "license per processor" the GetEnvironmentVariable() would be not
useful.


Thanks
 
Absent a mechanism that forces concurrent execution of multiple threads on
multiple processors, it is just a number.
 
Another possibility is to use WMI. The WMI
class Win32_ComputerSystem has a field NumberOfProcessors.
 
Back
Top