예제 #1
0
        double InitialiseMemoryLoad()
        {
            Computer computer = new Computer()
            {
                RAMEnabled = true
            };

            computer.Open();
            //computer.Accept(new HardwareInfo());
            foreach (var memory in computer.Hardware[0].Sensors)
            {
                if (memory.Name == "Memory")
                {
                    computer.Close();
                    return(Convert.ToDouble(memory.Value));
                }
            }
            return(0);
        }
예제 #2
0
        Dictionary <int, double> InitialiseCPULoad()
        {
            Computer computer = new Computer()
            {
                CPUEnabled = true
            };

            computer.Open();
            //computer.Accept(new HardwareInfo());
            string cpuCoreName = @"CPU Core #(\d)";
            string cpuNum      = @"\d";


            // TODO delete foreach
            Dictionary <int, double> keyValuePairs = new Dictionary <int, double>();

            foreach (var hardware in computer.Hardware)
            {
                if (hardware.HardwareType == HardwareType.CPU)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (Regex.IsMatch(sensor.Name, cpuCoreName, RegexOptions.IgnoreCase) && sensor.SensorType == SensorType.Load)
                        {
                            Match match = Regex.Match(sensor.Name, cpuNum);
                            if (match.Success)
                            {
                                keyValuePairs.Add(Convert.ToInt32(Char.GetNumericValue(sensor.Name[match.Index])), Convert.ToDouble(sensor.Value));
                            }
                        }
                    }
                    break;
                }
            }
            computer.Close();
            return(keyValuePairs);
        }