Fix for the following:

Warning CA1001 Type 'MainWindow' owns disposable field(s) '_firstDeleteTimer' but is not disposable PowerLauncher C:\Repos\PowerToys\src\modules\launcher\PowerLauncher\MainWindow.xaml.cs

    Warning CA1816 Change App.Dispose() to call GC.SuppressFinalize(object). This will prevent derived types that introduce a finalizer from needing to re-implement 'IDisposable' to call it. PowerLauncher C:\Repos\PowerToys\src\modules\launcher\PowerLauncher\App.xaml.cs
This commit is contained in:
ryanbodrug-microsoft 2020-06-17 16:53:41 -07:00
parent d6e2b096ca
commit 0f3b154699
2 changed files with 67 additions and 14 deletions

View File

@ -29,6 +29,7 @@ namespace PowerLauncher
private static int _powerToysPid;
private Settings _settings;
private MainViewModel _mainVM;
private MainWindow _mainWindow;
private SettingWindowViewModel _settingsVM;
private readonly Alphabet _alphabet = new Alphabet();
private StringMatcher _stringMatcher;
@ -78,11 +79,11 @@ namespace PowerLauncher
ThemeManager themeManager = new ThemeManager(this);
PluginManager.LoadPlugins(_settings.PluginSettings);
_mainVM = new MainViewModel(_settings);
var window = new MainWindow(_settings, _mainVM);
_mainWindow = new MainWindow(_settings, _mainVM);
API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet);
PluginManager.InitializePlugins(API);
Current.MainWindow = window;
Current.MainWindow = _mainWindow;
Current.MainWindow.Title = Constant.ExeFileName;
// happlebao todo temp fix for instance code logic
@ -161,20 +162,40 @@ namespace PowerLauncher
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
}
public void Dispose()
{
// if sessionending is called, exit proverbially be called when log off / shutdown
// but if sessionending is not called, exit won't be called when log off / shutdown
if (!_disposed)
{
API.SaveAppAllSettings();
_disposed = true;
}
}
public void OnSecondAppStarted()
{
Current.MainWindow.Visibility = Visibility.Visible;
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_mainWindow.Dispose();
API.SaveAppAllSettings();
_disposed = true;
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
_disposed = true;
}
}
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~App()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@ -16,9 +16,10 @@ using System.Timers;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Telemetry;
namespace PowerLauncher
{
public partial class MainWindow
public partial class MainWindow : IDisposable
{
#region Private Fields
@ -268,6 +269,8 @@ namespace PowerLauncher
private const int millisecondsToWait = 100;
private static DateTime s_lastTimeOfTyping;
private bool disposedValue = false;
private string ListView_FirstItem(String input)
{
if (!string.IsNullOrEmpty(input))
@ -356,5 +359,34 @@ namespace PowerLauncher
{
Hide();
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
_firstDeleteTimer.Dispose();
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
disposedValue = true;
}
}
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~MainWindow()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}