Skip to content

Commit 25940ed

Browse files
committed
* Fixed statistics not being displayed with auto optimisation
1 parent 17a514d commit 25940ed

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

MemPlus/Business/RAM/RamController.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44
using System.Timers;
5+
using System.Windows;
6+
using Hardcodet.Wpf.TaskbarNotification;
57
using MemPlus.Business.LOG;
68
using MemPlus.Views.Windows;
79
using Microsoft.VisualBasic.Devices;
@@ -190,7 +192,7 @@ internal void EnableMonitor()
190192

191193
_ramTimer.Enabled = true;
192194
RamMonitorEnabled = true;
193-
195+
194196
UpdateRamUsage();
195197
UpdateGuiControls();
196198

@@ -271,6 +273,8 @@ await Task.Run(async () =>
271273
RamSavings = oldUsage - newUsage;
272274
});
273275

276+
ClearingStatistcs();
277+
274278
_logController.AddLog(new ApplicationLog("Done clearing RAM memory"));
275279
}
276280

@@ -300,6 +304,8 @@ await Task.Run(async () =>
300304
RamSavings = oldUsage - newUsage;
301305
});
302306

307+
ClearingStatistcs();
308+
303309
_logController.AddLog(new ApplicationLog("Done clearing process working sets"));
304310
}
305311

@@ -327,9 +333,45 @@ await Task.Run(() =>
327333
RamSavings = oldUsage - newUsage;
328334
});
329335

336+
ClearingStatistcs();
337+
330338
_logController.AddLog(new ApplicationLog("Done clearing FileSystem cache"));
331339
}
332340

341+
/// <summary>
342+
/// Display a message about the last RAM Optimizer clearing statistics
343+
/// </summary>
344+
private void ClearingStatistcs()
345+
{
346+
double ramSavings = RamSavings / 1024 / 1024;
347+
string message;
348+
if (ramSavings < 0)
349+
{
350+
ramSavings = Math.Abs(ramSavings);
351+
_logController.AddLog(new RamLog("RAM usage increase: " + ramSavings.ToString("F2") + " MB"));
352+
message = "Looks like your RAM usage has increased with " + ramSavings.ToString("F2") + " MB!";
353+
}
354+
else
355+
{
356+
_logController.AddLog(new RamLog("RAM usage decrease: " + ramSavings.ToString("F2") + " MB"));
357+
message = "You saved " + ramSavings.ToString("F2") + " MB of RAM!";
358+
}
359+
360+
if (ShowStatistics)
361+
{
362+
// ReSharper disable once SwitchStatementMissingSomeCases
363+
switch (_mainWindow.Visibility)
364+
{
365+
default:
366+
MessageBox.Show(message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
367+
break;
368+
case Visibility.Hidden when _mainWindow.TbiIcon.Visibility == Visibility.Visible:
369+
_mainWindow.TbiIcon.ShowBalloonTip("MemPlus", message, BalloonIcon.Info);
370+
break;
371+
}
372+
}
373+
}
374+
333375
/// <summary>
334376
/// Update RAM usage statistics
335377
/// </summary>

MemPlus/Views/Windows/MainWindow.xaml.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -702,34 +702,6 @@ private async void ClearMemory(int index)
702702
break;
703703
}
704704

705-
double ramSavings = _ramController.RamSavings / 1024 / 1024;
706-
string message;
707-
if (ramSavings < 0)
708-
{
709-
ramSavings = Math.Abs(ramSavings);
710-
_logController.AddLog(new RamLog("RAM usage increase: " + ramSavings.ToString("F2") + " MB"));
711-
message = "Looks like your RAM usage has increased with " + ramSavings.ToString("F2") + " MB!";
712-
}
713-
else
714-
{
715-
_logController.AddLog(new RamLog("RAM usage decrease: " + ramSavings.ToString("F2") + " MB"));
716-
message = "You saved " + ramSavings.ToString("F2") + " MB of RAM!";
717-
}
718-
719-
if (_statisticsMessage)
720-
{
721-
// ReSharper disable once SwitchStatementMissingSomeCases
722-
switch (Visibility)
723-
{
724-
default:
725-
MessageBox.Show(message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
726-
break;
727-
case Visibility.Hidden when TbiIcon.Visibility == Visibility.Visible:
728-
TbiIcon.ShowBalloonTip("MemPlus", message, BalloonIcon.Info);
729-
break;
730-
}
731-
}
732-
733705
BtnClearMemory.IsEnabled = true;
734706
}
735707
catch (Exception ex)

0 commit comments

Comments
 (0)