Ejemplo n.º 1
0
        public static CPUInfo ReadCPUInfo()
        {
            CPUInfo cpu = new CPUInfo();

            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Name, MaxClockSpeed, NumberOfCores, NumberOfLogicalProcessors FROM Win32_Processor");
                Dictionary<string, string> data = new Dictionary<string, string>();

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (queryObj["Name"] != null)
                    {
                        cpu.Name = queryObj["Name"] as string;
                    }

                    if (queryObj["MaxClockSpeed"] != null)
                    {
                        cpu.MaxClockSpeed = uint.Parse(queryObj["MaxClockSpeed"].ToString());
                    }

                    if (queryObj["NumberOfCores"] != null)
                    {
                        cpu.NumberOfCores = int.Parse(queryObj["NumberOfCores"].ToString());
                    }

                    if (queryObj["NumberOfLogicalProcessors"] != null)
                    {
                        cpu.NumberOfLogicalProcessors = int.Parse(queryObj["NumberOfLogicalProcessors"].ToString());
                    }

                    break;
                }
            }
            catch(Exception e)
            {
                cpu.Name = "Error getting CPU info: " + e.Message;
            }
            finally
            { }

            return cpu;
        }
Ejemplo n.º 2
0
        public static CPUInfo ReadCPUInfo()
        {
            CPUInfo cpu = new CPUInfo();

            try
            {
                ManagementObjectSearcher    searcher = new ManagementObjectSearcher("SELECT Name, MaxClockSpeed, NumberOfCores, NumberOfLogicalProcessors FROM Win32_Processor");
                Dictionary <string, string> data     = new Dictionary <string, string>();

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (queryObj["Name"] != null)
                    {
                        cpu.Name = queryObj["Name"] as string;
                    }

                    if (queryObj["MaxClockSpeed"] != null)
                    {
                        cpu.MaxClockSpeed = uint.Parse(queryObj["MaxClockSpeed"].ToString());
                    }

                    if (queryObj["NumberOfCores"] != null)
                    {
                        cpu.NumberOfCores = int.Parse(queryObj["NumberOfCores"].ToString());
                    }

                    if (queryObj["NumberOfLogicalProcessors"] != null)
                    {
                        cpu.NumberOfLogicalProcessors = int.Parse(queryObj["NumberOfLogicalProcessors"].ToString());
                    }

                    break;
                }
            }
            catch (Exception e)
            {
                cpu.Name = "Error getting CPU info: " + e.Message;
            }
            finally
            { }

            return(cpu);
        }