Get Cpu Info - CSharp Operating System

CSharp examples for Operating System:Cpu

Description

Get Cpu Info

Demo Code


using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Management;
using System.Text;
using System.Collections.Generic;
using System;//from  ww  w .j  av  a 2 s.c  om

public class Main{
    
        public static List<CpuInfo> GetCpuInfo()
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\CIMV2", "SELECT * FROM Win32_Processor");
            ManagementObjectCollection list = searcher.Get();
            uint count = 0;
            foreach (ManagementObject obj2 in list)
            {
                ++count;
            }
            List<CpuInfo> cpuList = new List<CpuInfo>();
            foreach (ManagementObject obj2 in list)
            {
                cpuList.Add(new CpuInfo(obj2.GetPropertyValue("Name").ToString(), (uint)obj2.GetPropertyValue("CurrentClockSpeed"), (uint)(Environment.ProcessorCount / count)));
            }
            return cpuList;
        }
}

Related Tutorials