コード例 #1
0
ファイル: ComputerInfo.cs プロジェクト: adamsp/beastmon
        public static void Monitor()
        {
            running = true;
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer computer = new Computer();

            computer.Open();

            while (running)
            {
                computer.Accept(updateVisitor);
                MonitoringInfo currentInfo = new MonitoringInfo();

                foreach (IHardware hardware in computer.Hardware)
                {
                    if (hardware.HardwareType == HardwareType.CPU)
                    {
                        CPU cpu = new CPU();
                        AddCPUInfo(hardware.Sensors, cpu);

                        currentInfo.CPUs.Add(cpu);
                    }
                    else if (hardware.HardwareType == HardwareType.GpuAti)
                    {
                        GPU gpu = new GPU();
                        gpu.GPUTempMax = 100; // assume max gpu temp is 100 *C
                        AddGPUInfo(hardware.Sensors, gpu);

                        currentInfo.GPUs.Add(gpu);
                    }
                    else if (hardware.HardwareType == HardwareType.GpuNvidia)
                    {
                        GPU gpu = new GPU();
                        gpu.GPUTempMax = 100; // assume max gpu temp is 100 *C
                        AddGPUInfo(hardware.Sensors, gpu);

                        currentInfo.GPUs.Add(gpu);
                    }
                }

                RAM ram = new RAM();
                MEMORYSTATUSEX memoryUsage = new MEMORYSTATUSEX();
                if (GlobalMemoryStatusEx(memoryUsage))
                {
                    ram.FreeMemory = (int)(memoryUsage.ullAvailPhys / (1024 * 1024)); // in MB
                    ram.TotalMemory = (int)(memoryUsage.ullTotalPhys / (1024 * 1024)); // in MB
                }

                currentInfo.RAM = ram;

                Info = currentInfo;

                Thread.Sleep(1000);
            }
        }
コード例 #2
0
ファイル: ComputerInfo.cs プロジェクト: okonk/beastmon
 private static void AddGPUInfo(ISensor[] sensors, GPU gpu)
 {
     foreach (ISensor sensor in sensors)
     {
         if (sensor.SensorType == SensorType.Load)
         {
             gpu.GPULoad = sensor.Value.Value;
         }
         else if (sensor.SensorType == SensorType.Temperature)
         {
             gpu.GPUTemp = sensor.Value.Value;
         }
     }
 }