@@ -242,37 +242,9 @@ internal void ChangeVisualStyle()
242242 /// </summary>
243243 /// <param name="sender">The object that called this method</param>
244244 /// <param name="e">The RoutedEventArgs</param>
245- private async void BtnClearMemory_OnClick ( object sender , RoutedEventArgs e )
245+ private void BtnClearMemory_OnClick ( object sender , RoutedEventArgs e )
246246 {
247- _logController . AddLog ( new ApplicationLog ( "Clearing RAM Memory" ) ) ;
248-
249- try
250- {
251- BtnClearMemory . IsEnabled = false ;
252-
253- await _ramController . ClearMemory ( ) ;
254- double ramSavings = _ramController . RamSavings / 1024 / 1024 ;
255- if ( ramSavings < 0 )
256- {
257- ramSavings = Math . Abs ( ramSavings ) ;
258- _logController . AddLog ( new RamLog ( "RAM usage increase: " + ramSavings . ToString ( "F2" ) + " MB" ) ) ;
259- MessageBox . Show ( "Looks like your RAM usage has increased with " + ramSavings . ToString ( "F2" ) + " MB!" , "MemPlus" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
260- }
261- else
262- {
263- _logController . AddLog ( new RamLog ( "RAM usage decrease: " + ramSavings . ToString ( "F2" ) + " MB" ) ) ;
264- MessageBox . Show ( "You saved " + ramSavings . ToString ( "F2" ) + " MB of RAM!" , "MemPlus" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
265- }
266-
267- BtnClearMemory . IsEnabled = true ;
268- }
269- catch ( Exception ex )
270- {
271- _logController . AddLog ( new ApplicationLog ( ex . Message ) ) ;
272- MessageBox . Show ( ex . Message , "MemPlus" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
273- }
274-
275- _logController . AddLog ( new ApplicationLog ( "Done clearing RAM memory" ) ) ;
247+ ClearMemory ( 0 ) ;
276248 }
277249
278250 /// <summary>
@@ -676,5 +648,60 @@ private void RestartMenuItem_OnClick(object sender, RoutedEventArgs e)
676648 MessageBox . Show ( ex . Message , "MemPlus" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
677649 }
678650 }
651+
652+ private void ClearWorkingSetsDropDownMenuItem_OnClick ( object sender , RoutedEventArgs e )
653+ {
654+ ClearMemory ( 1 ) ;
655+ }
656+
657+ private void ClearFileSystemCacheDropDownMenuItem_OnClick ( object sender , RoutedEventArgs e )
658+ {
659+ ClearMemory ( 2 ) ;
660+ }
661+
662+ private async void ClearMemory ( int index )
663+ {
664+ _logController . AddLog ( new ApplicationLog ( "Clearing RAM Memory" ) ) ;
665+
666+ try
667+ {
668+ BtnClearMemory . IsEnabled = false ;
669+
670+ switch ( index )
671+ {
672+ case 0 :
673+ await _ramController . ClearMemory ( ) ;
674+ break ;
675+ case 1 :
676+ await _ramController . ClearWorkingSets ( ) ;
677+ break ;
678+ case 2 :
679+ await _ramController . ClearFileSystemCaches ( ) ;
680+ break ;
681+ }
682+
683+ double ramSavings = _ramController . RamSavings / 1024 / 1024 ;
684+ if ( ramSavings < 0 )
685+ {
686+ ramSavings = Math . Abs ( ramSavings ) ;
687+ _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 ) ;
689+ }
690+ else
691+ {
692+ _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 ) ;
694+ }
695+
696+ BtnClearMemory . IsEnabled = true ;
697+ }
698+ catch ( Exception ex )
699+ {
700+ _logController . AddLog ( new ApplicationLog ( ex . Message ) ) ;
701+ MessageBox . Show ( ex . Message , "MemPlus" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
702+ }
703+
704+ _logController . AddLog ( new ApplicationLog ( "Done clearing RAM memory" ) ) ;
705+ }
679706 }
680707}
0 commit comments