ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_Processor"); int count = 0;//核心数 foreach (ManagementObject obj in searcher.Get()) { object cores = obj["NumberOfCores"]; if (cores == null) { break; } string numberOfCores = obj["NumberOfCores"].ToString(); int coreCount; bool success = int.TryParse(numberOfCores, out coreCount); if (success) { count ++; } }