C#取CPU核心数的算法

 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 ++;
                }
            }
posted @ 2010-12-14 15:56  kiminozo  阅读(2890)  评论(1编辑  收藏  举报