Skip to content

Commit 9b23906

Browse files
committed
* Added ability to view total physical memory
* Added ability to view available physical memory * Design changes to Main Window * Code improvements
1 parent adb97b7 commit 9b23906

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

MemPlus/Classes/RAM/RamController.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
using System;
22
using System.Threading.Tasks;
33
using System.Timers;
4+
using System.Windows.Controls;
45
using System.Windows.Threading;
56
using Microsoft.VisualBasic.Devices;
67
using Syncfusion.UI.Xaml.Gauges;
78

89
namespace MemPlus.Classes.RAM
910
{
10-
internal class RamController
11+
internal sealed class RamController
1112
{
1213
private readonly Timer _ramTimer;
14+
1315
private readonly Dispatcher _dispatcher;
1416
private readonly SfCircularGauge _gauge;
17+
private readonly Label _lblTotal;
18+
private readonly Label _lblAvailable;
19+
1520
private readonly ComputerInfo _info;
1621

1722
internal double RamUsage { get; private set; }
1823
internal double RamUsagePercentage { get; private set; }
1924
internal double RamTotal { get; private set; }
2025
internal double RamSavings { get; private set; }
2126

22-
internal RamController(Dispatcher dispatcher, SfCircularGauge gauge, int timerInterval)
27+
internal RamController(Dispatcher dispatcher, SfCircularGauge gauge, Label lblTotal, Label lblAvailable, int timerInterval)
2328
{
2429
if (timerInterval <= 0) throw new ArgumentException("Timer interval cannot be less than or equal to zero!");
2530

2631
RamSavings = 0;
2732

2833
_info = new ComputerInfo();
34+
2935
_dispatcher = dispatcher ?? throw new ArgumentException("Dispatcher cannot be null!");
3036
_gauge = gauge ?? throw new ArgumentException("Gauge cannot be null!");
37+
_lblTotal = lblTotal ?? throw new ArgumentNullException(nameof(lblTotal));
38+
_lblAvailable = lblAvailable ?? throw new ArgumentNullException(nameof(lblAvailable));
3139

3240
_ramTimer = new Timer();
3341
_ramTimer.Elapsed += OnTimedEvent;
@@ -53,19 +61,16 @@ private void OnTimedEvent(object source, ElapsedEventArgs e)
5361
{
5462
_gauge.Scales[0].Pointers[0].Value = RamUsagePercentage;
5563
_gauge.GaugeHeader = "RAM usage (" + RamUsagePercentage.ToString("F2") + "%)";
64+
65+
_lblTotal.Content = (RamTotal / 1024 / 1024 / 1024).ToString("F2") + " GB";
66+
_lblAvailable.Content = ((RamTotal - RamUsage) / 1024 / 1024 / 1024).ToString("F2") + " GB";
5667
});
5768
}
5869

5970
internal async Task ClearMemory(bool filesystemcache)
6071
{
61-
await Task.Run(() =>
72+
await Task.Run(async () =>
6273
{
63-
bool wasEnabled = _ramTimer.Enabled;
64-
if (wasEnabled)
65-
{
66-
DisableMonitor();
67-
}
68-
6974
UpdateRamUsage();
7075

7176
double oldUsage = RamUsage;
@@ -75,15 +80,12 @@ await Task.Run(() =>
7580
//Clear file system cache
7681
MemPlus.ClearFileSystemCache(filesystemcache);
7782

83+
await Task.Delay(10000);
84+
7885
UpdateRamUsage();
7986
double newUsage = RamUsage;
8087

8188
RamSavings = oldUsage - newUsage;
82-
83-
if (wasEnabled)
84-
{
85-
EnableMonitor();
86-
}
8789
});
8890
}
8991

MemPlus/Windows/MainWindow.xaml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
mc:Ignorable="d"
99
UseLayoutRounding="True"
1010
TitleTextAlignment="Center"
11-
Title="MemPlus" Height="400" Width="450" WindowStartupLocation="CenterScreen" Icon="/MemPlus;component/Resources/ram.png">
11+
Title="MemPlus" Height="300" Width="500" WindowStartupLocation="CenterScreen" Icon="/MemPlus;component/Resources/ram.png">
1212
<Grid>
1313
<Grid.RowDefinitions>
1414
<RowDefinition Height="Auto"></RowDefinition>
@@ -50,10 +50,11 @@
5050
</Menu>
5151

5252
<Grid Grid.Row="1" Visibility="Visible">
53-
<Grid.RowDefinitions>
54-
<RowDefinition></RowDefinition>
55-
<RowDefinition Height="Auto"></RowDefinition>
56-
</Grid.RowDefinitions>
53+
<Grid.ColumnDefinitions>
54+
<ColumnDefinition></ColumnDefinition>
55+
<ColumnDefinition Width="Auto"></ColumnDefinition>
56+
<ColumnDefinition></ColumnDefinition>
57+
</Grid.ColumnDefinitions>
5758

5859
<syncfusion:SfCircularGauge Grid.Row="0" x:Name="CgRamUsage"
5960
GaugeHeader="RAM usage (%)"
@@ -69,8 +70,26 @@
6970
</syncfusion:CircularScale>
7071
</syncfusion:SfCircularGauge.Scales>
7172
</syncfusion:SfCircularGauge>
73+
<Separator Margin="5,10" Grid.Column="1" Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
7274

73-
<Button x:Name="BtnClearMemory" Grid.Row="1" Content="Clear memory" Click="BtnClearMemory_OnClick" MinHeight="25" />
75+
<Grid Grid.Column="2" VerticalAlignment="Center">
76+
<Grid.RowDefinitions>
77+
<RowDefinition Height="Auto"></RowDefinition>
78+
<RowDefinition Height="Auto"></RowDefinition>
79+
<RowDefinition Height="Auto"></RowDefinition>
80+
<RowDefinition Height="Auto"></RowDefinition>
81+
<RowDefinition Height="Auto"></RowDefinition>
82+
<RowDefinition Height="Auto"></RowDefinition>
83+
<RowDefinition Height="*"></RowDefinition>
84+
</Grid.RowDefinitions>
85+
86+
<Label Content="Total physical memory:" FontSize="14" Margin="10,5" />
87+
<Label x:Name="LblTotalPhysicalMemory" Grid.Row="2" Content="" FontSize="14" Foreground="Green" Margin="10,5" />
88+
<Label Grid.Row="3" Content="Available physical memory:" FontSize="14" Margin="10,5" />
89+
<Label x:Name="LblAvailablePhysicalMemory" Grid.Row="4" Content="" FontSize="14" Foreground="Red" Margin="10,5" />
90+
91+
<Button Grid.Row="5" x:Name="BtnClearMemory" Content="Clear memory" Click="BtnClearMemory_OnClick" Margin="10,5" FontSize="14"/>
92+
</Grid>
7493
</Grid>
7594
</Grid>
7695
</syncfusion:ChromelessWindow>

MemPlus/Windows/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public MainWindow()
1919
InitializeComponent();
2020
ChangeVisualStyle();
2121

22-
_ramController = new RamController(Dispatcher, CgRamUsage, 5000);
22+
_ramController = new RamController(Dispatcher, CgRamUsage,LblTotalPhysicalMemory, LblAvailablePhysicalMemory, 5000);
2323
_ramController.EnableMonitor();
2424
}
2525

0 commit comments

Comments
 (0)