33![ Downloads] ( https://img.shields.io/github/downloads/sergiye/openhardwaremonitor/total?style=for-the-badge&color=ff4f42 )
44![ Last commit] ( https://img.shields.io/github/last-commit/sergiye/openhardwaremonitor?style=for-the-badge&color=00AD00 )
55
6- [ ![ Nuget] ( https://img.shields.io/nuget/v/OpenHardwareMonitorLib?style=for-the-badge )] ( https://www.nuget.org/packages/OpenHardwareMonitorLib/ )
6+ [ ![ Nuget] ( https://img.shields.io/nuget/v/OpenHardwareMonitorLib?style=for-the-badge )] ( https://www.nuget.org/packages/OpenHardwareMonitorLib/ )
77[ ![ Nuget] ( https://img.shields.io/nuget/dt/OpenHardwareMonitorLib?label=nuget-downloads&style=for-the-badge )] ( https://www.nuget.org/packages/OpenHardwareMonitorLib/ )
88
99Open hardware monitor - is free software that can monitor the temperature sensors, fan speeds, voltages, load and clock speeds of your computer.
@@ -12,14 +12,14 @@ This application is based on the "original" [openhardwaremonitor](https://github
1212
1313----
1414
15- [ < img src = " https://github.com/sergiye/hiberbeeTheme/raw/master/assets/ukraine_flag_bar.png " alt = " UA " /> ] ( https://u24.gov.ua )
15+ [ ![ UA ] ( https://github.com/sergiye/hiberbeeTheme/raw/master/assets/ukraine_flag_bar.png ) ]( https://u24.gov.ua )
1616
1717
1818Support the Armed Forces of Ukraine and People Affected by Russia’s Aggression on UNITED24, the official fundraising platform of Ukraine: https://u24.gov.ua .
1919
2020** Слава Україні!**
2121
22- [ < img src = " https://github.com/sergiye/hiberbeeTheme/raw/master/assets/ukraine_flag_bar.png " alt = " UA " /> ] ( https://u24.gov.ua )
22+ [ ![ UA ] ( https://github.com/sergiye/hiberbeeTheme/raw/master/assets/ukraine_flag_bar.png ) ]( https://u24.gov.ua )
2323
2424
2525## Features
@@ -38,17 +38,17 @@ You can see information about devices such as:
3838
3939### Additional features
4040
41- - ` Remote web-server ` mode for browsing data from remote machine with custom port and authentification .
41+ - ` Remote web-server ` mode for browsing data from remote machine with custom port and authentication .
4242 - ` Hide/Unhide ` sensors to remove some data from UI and web server.
4343 - Multiple ` Tray icons ` and ` Gadget ` for selected sensor values.
4444 - ` Light ` /` Dark ` themes with auto switching mode.
4545 - Custom ` color-themes ` from external files - You can find examples [ here] ( https://github.com/sergiye/openhardwaremonitor/tree/dev/OpenHardwareMonitor/Resources/themes )
4646 - ` Portable ` mode for storing temporary driver file and settings configuration next to the executable file.
4747 - ` Updated versions check ` - manually from main menu.
48-
48+
4949 Note: Some sensors are only available when running the application as administrator.
5050
51- ### UI example with ` Light ` /` Dark ` themes
51+ ### UI example with ` Light ` /` Dark ` themes
5252
5353[ <img src =" https://github.com/sergiye/openhardwaremonitor/raw/master/themes.png " alt =" Themes " width =" 300 " />] ( https://github.com/sergiye/openhardwaremonitor/releases )
5454
@@ -70,48 +70,36 @@ You can see information about devices such as:
7070
7171** Sample code**
7272``` c#
73- public class UpdateVisitor : IVisitor {
74- public void VisitComputer (IComputer computer ) {
75- computer .Traverse (this );
76- }
77- public void VisitHardware (IHardware hardware ) {
78- hardware .Update ();
79- foreach (IHardware subHardware in hardware .SubHardware ) subHardware .Accept (this );
80- }
81- public void VisitSensor (ISensor sensor ) { }
82- public void VisitParameter (IParameter parameter ) { }
83- }
73+ class HardwareInfoProvider : IVisitor , IDisposable {
8474
85- public void Monitor () {
86- Computer computer = new Computer {
87- IsCpuEnabled = true ,
88- IsGpuEnabled = true ,
89- IsMemoryEnabled = true ,
90- IsMotherboardEnabled = true ,
91- IsControllerEnabled = true ,
92- IsNetworkEnabled = true ,
93- IsBatteryEnabled = true ,
94- IsStorageEnabled = true
95- };
75+ private readonly Computer computer ;
9676
77+ public HardwareInfoProvider () {
78+ computer = new Computer {
79+ IsCpuEnabled = true ,
80+ IsMemoryEnabled = true ,
81+ };
9782 computer .Open (false );
98- computer .Accept (new UpdateVisitor ());
99-
100- foreach (IHardware hardware in computer .Hardware ) {
101- Console .WriteLine (" Hardware: {0}" , hardware .Name );
102- foreach (IHardware subhardware in hardware .SubHardware ) {
103- Console .WriteLine (" \t Subhardware: {0}" , subhardware .Name );
104- foreach (ISensor sensor in subhardware .Sensors ) {
105- Console .WriteLine (" \t\t Sensor: {0}, value: {1}" , sensor .Name , sensor .Value );
106- }
107- }
108-
109- foreach (ISensor sensor in hardware .Sensors ) {
110- Console .WriteLine (" \t Sensor: {0}, value: {1}" , sensor .Name , sensor .Value );
111- }
112- }
113-
114- computer .Close ();
83+ }
84+
85+ internal float Cpu { get ; private set ; }
86+ internal float Memory { get ; private set ; }
87+
88+ public void VisitComputer (IComputer computer ) => computer .Traverse (this );
89+ public void VisitHardware (IHardware hardware ) => hardware .Update ();
90+ public void VisitSensor (ISensor sensor ) { }
91+ public void VisitParameter (IParameter parameter ) { }
92+ public void Dispose () => computer .Close ();
93+
94+ internal void Refresh () {
95+ computer .Accept (this );
96+ var cpuTotal = computer .Hardware .FirstOrDefault (h => h .HardwareType == HardwareType .Cpu )? .Sensors .FirstOrDefault (s => s .SensorType == SensorType .Load && s .Name == " CPU Total" );
97+ Cpu = cpuTotal ? .Value ?? - 1 ;
98+
99+ var memorySensorName = " Physical Memory Available" ; // "Virtual Memory Available";
100+ var memUsed = computer .Hardware .FirstOrDefault (h => h .HardwareType == HardwareType .Memory )? .Sensors .FirstOrDefault (s => s .SensorType == SensorType .Data && s .Name == memorySensorName );
101+ Memory = (memUsed == null || ! memUsed .Value .HasValue ) ? - 1 : memUsed .Value .Value * 1024 ; // GB -> MB
102+ }
115103}
116104```
117105
0 commit comments