Get the ID number of the CPU in C #

Source: Internet
Author: User

The System.Management namespace provides access to a wide range of management information and management event collections related to system, device, and application setting checkpoints based on the Windows Management Instrumentation (WMI) architecture. Applications and services can use classes derived from ManagementObjectSearcher and managementquery to query for administrative information of interest (for example, how much free space is left on the disk, what is the current CPU utilization, Which database an application is connecting to, and so on), or that applications and services can subscribe to a variety of administrative events using the ManagementEventWatcher class. These accessible data can come from managed and unmanaged components in a distributed environment. Use the ManagementClass class under the System.Management namespace to get the CPU number. First, add a reference to the System.Management class library. You can then add the following code to get the number of the CPU.

System.Management.ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
MessageBox.Show(mo["processorid"].ToString());
}

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.