如何在C#中获取CPU的逻辑内核/线程数?
发布时间:2020-12-15 03:59:49 所属栏目:百科 来源:网络整理
导读:如何获得CPU中的逻辑内核数? 我需要这个来确定我应用程序中应该运行多少个线程. 解决方法 您可以通过Environment类获得多个逻辑处理器 核心数: int coreCount = 0;foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Wi
如何获得CPU中的逻辑内核数?
我需要这个来确定我应用程序中应该运行多少个线程. 解决方法
您可以通过Environment类获得多个逻辑处理器
核心数: 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); 逻辑处理器数量 foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_ComputerSystem").Get()) { Console.WriteLine("Number Of Logical Processors: {0}",item["NumberOfLogicalProcessors"]); } Environment.ProcessorCount using System; class Sample { public static void Main() { Console.WriteLine("The number of processors on this computer is {0}.",Environment.ProcessorCount); } } 通过这个链接http://msdn.microsoft.com/en-us/library/system.environment.processorcount.aspx (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |