Use C # To obtain the ID of the CPU

Source: Internet
Author: User

System. the Management namespace provides access to a large number of Management information and Management event sets, which are consistent with Windows Management specifications (WMI) structure is related to Setting Detection Points for systems, devices, and applications. Applications and Services can use classes derived from ManagementObjectSearcher and ManagementQuery, query the management information you are interested in (for example, the amount of available space on the disk, the current CPU usage, and the database to which an application is connected ); or applications and services can use the ManagementEventWatcher class to book various management events. These accessible data can come from hosted and unmanaged components in a distributed environment. You can use the ManagementClass class in the System. Management namespace to obtain the CPU number. First, add a reference to the System. Management class library. Then add the following code to obtain 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 ());
}

Related Article

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.