using System;
namespace GetProcessorCountCmd
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine($"Environment.ProcessorCount: {Environment.ProcessorCount}");
Print();
Console.WriteLine("Press <Enter> to exit.");
Console.ReadLine();
}
static void Print()
{
foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_ComputerSystem").Get())
{
Console.WriteLine("Number Of Physical Processors: {0} ", item["NumberOfProcessors"]);
}
// Number of Cores
int coreCount = 0;
foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get())
{
coreCount += int.Parse(item["NumberOfCores"].ToString());
}
Console.WriteLine("Number Of Cores: {0}", coreCount);
// Number of Logical Processors
foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_ComputerSystem").Get())
{
Console.WriteLine("Number Of Logical Processors: {0}", item["NumberOfLogicalProcessors"]);
}
}
}
}
Windows Task Manager:![image](https://user-images.githubusercontent.com/1849690/69044690-0779fe00-09fe-11ea-87bf-4c01eba1858e.png)
https://stackoverflow.com/questions/1542213/how-to-find-the-number-of-cpu-cores-via-net-c