@@ -32,6 +32,14 @@ public partial class MainWindow
3232 /// The LogController object that can be used to add new logs
3333 /// </summary>
3434 private readonly LogController _logController ;
35+ /// <summary>
36+ /// A boolean to indicate whether RAM statistics should be displayed after clearing the memory
37+ /// </summary>
38+ private bool _statisticsMessage ;
39+ /// <summary>
40+ /// A boolean to indicate whether RAM cleaning is currently in progress
41+ /// </summary>
42+ private bool _clearingMemory ;
3543 #endregion
3644
3745 /// <inheritdoc />
@@ -42,7 +50,9 @@ public MainWindow()
4250 {
4351 _logController = new LogController ( 600000 ) ;
4452 _logController . AddLog ( new ApplicationLog ( "Initializing MainWindow" ) ) ;
53+
4554 _updateManager = new UpdateManager . Classes . UpdateManager ( Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version , "https://codedead.com/Software/MemPlus/update.xml" , "MemPlus" , "Information" , "Cancel" , "Download" , "No new version is currently available." ) ;
55+ _clearingMemory = false ;
4656
4757 InitializeComponent ( ) ;
4858 ChangeVisualStyle ( ) ;
@@ -123,6 +133,7 @@ internal void LoadProperties()
123133
124134 try
125135 {
136+ _statisticsMessage = Properties . Settings . Default . RamCleaningMessage ;
126137 MniDisableInactive . IsChecked = Properties . Settings . Default . DisableOnInactive ;
127138 MniOnTop . IsChecked = Properties . Settings . Default . Topmost ;
128139 MniRamMonitor . IsChecked = Properties . Settings . Default . RamMonitor ;
@@ -649,24 +660,42 @@ private void RestartMenuItem_OnClick(object sender, RoutedEventArgs e)
649660 }
650661 }
651662
663+ /// <summary>
664+ /// Method that is called when the working set of processes should be cleared
665+ /// </summary>
666+ /// <param name="sender">The object that called this method</param>
667+ /// <param name="e">The RoutedEventArgs</param>
652668 private void ClearWorkingSetsDropDownMenuItem_OnClick ( object sender , RoutedEventArgs e )
653669 {
654670 ClearMemory ( 1 ) ;
655671 }
656672
673+ /// <summary>
674+ /// Method that is called when the FileSystem cache should be cleared
675+ /// </summary>
676+ /// <param name="sender">The object that called this method</param>
677+ /// <param name="e">The RoutedEventArgs</param>
657678 private void ClearFileSystemCacheDropDownMenuItem_OnClick ( object sender , RoutedEventArgs e )
658679 {
659680 ClearMemory ( 2 ) ;
660681 }
661682
683+ /// <summary>
684+ /// Clear the memory
685+ /// </summary>
686+ /// <param name="index">The type of memory that needs to be cleared</param>
662687 private async void ClearMemory ( int index )
663688 {
689+ if ( _clearingMemory ) return ;
690+
664691 _logController . AddLog ( new ApplicationLog ( "Clearing RAM Memory" ) ) ;
692+ _clearingMemory = true ;
665693
666694 try
667695 {
668696 BtnClearMemory . IsEnabled = false ;
669697
698+ // ReSharper disable once SwitchStatementMissingSomeCases
670699 switch ( index )
671700 {
672701 case 0 :
@@ -685,12 +714,18 @@ private async void ClearMemory(int index)
685714 {
686715 ramSavings = Math . Abs ( ramSavings ) ;
687716 _logController . AddLog ( new RamLog ( "RAM usage increase: " + ramSavings . ToString ( "F2" ) + " MB" ) ) ;
688- MessageBox . Show ( "Looks like your RAM usage has increased with " + ramSavings . ToString ( "F2" ) + " MB!" , "MemPlus" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
717+ if ( _statisticsMessage )
718+ {
719+ MessageBox . Show ( "Looks like your RAM usage has increased with " + ramSavings . ToString ( "F2" ) + " MB!" , "MemPlus" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
720+ }
689721 }
690722 else
691723 {
692724 _logController . AddLog ( new RamLog ( "RAM usage decrease: " + ramSavings . ToString ( "F2" ) + " MB" ) ) ;
693- MessageBox . Show ( "You saved " + ramSavings . ToString ( "F2" ) + " MB of RAM!" , "MemPlus" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
725+ if ( _statisticsMessage )
726+ {
727+ MessageBox . Show ( "You saved " + ramSavings . ToString ( "F2" ) + " MB of RAM!" , "MemPlus" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
728+ }
694729 }
695730
696731 BtnClearMemory . IsEnabled = true ;
@@ -701,6 +736,7 @@ private async void ClearMemory(int index)
701736 MessageBox . Show ( ex . Message , "MemPlus" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
702737 }
703738
739+ _clearingMemory = false ;
704740 _logController . AddLog ( new ApplicationLog ( "Done clearing RAM memory" ) ) ;
705741 }
706742 }
0 commit comments