C # Methods for acquiring the core number of CPU processors _c# Tutorial

Source: Internet
Author: User

There are several different processor information that you can get information about: The number of physical processors, core quantities, and number of logical processors, which can be different. Two dual-core Hyper-Threading (enabled) processors are available in the case of 2 physical processors, 4 cores, and 8 logical processors.

The number of logical processors is obtained through the environment class, but other information is available only through WMI (you may need to install some patches or service packs):

Physical Processor:

foreach (var item in the New System.Management.ManagementObjectSearcher ("SELECT * from Win32_ComputerSystem"). Get ())
{
 Console.WriteLine ("Number of physical processors: {0}", item["NumberOfProcessors"]);

Kernel:

int corecount = 0;
foreach (var item in the New System.Management.ManagementObjectSearcher ("SELECT * from Win32_Processor"). Get ())
{
 corecount = Int. Parse (item["NumberOfCores"). ToString ());
}
Console.WriteLine ("Number of cores: {0}", Corecount);

Logical Processor:

Console.WriteLine("Number Of Logical Processors: {0}", Environment.ProcessorCount);

Or

foreach (var item in the New System.Management.ManagementObjectSearcher ("SELECT * from Win32_ComputerSystem"). Get ())
{
 Console.WriteLine ("Number of Logical processors: {0}", item["numberoflogicalprocessors"]);

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.