mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
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:
parent
d6e2b096ca
commit
0f3b154699
@ -29,6 +29,7 @@ namespace PowerLauncher
|
|||||||
private static int _powerToysPid;
|
private static int _powerToysPid;
|
||||||
private Settings _settings;
|
private Settings _settings;
|
||||||
private MainViewModel _mainVM;
|
private MainViewModel _mainVM;
|
||||||
|
private MainWindow _mainWindow;
|
||||||
private SettingWindowViewModel _settingsVM;
|
private SettingWindowViewModel _settingsVM;
|
||||||
private readonly Alphabet _alphabet = new Alphabet();
|
private readonly Alphabet _alphabet = new Alphabet();
|
||||||
private StringMatcher _stringMatcher;
|
private StringMatcher _stringMatcher;
|
||||||
@ -78,11 +79,11 @@ namespace PowerLauncher
|
|||||||
ThemeManager themeManager = new ThemeManager(this);
|
ThemeManager themeManager = new ThemeManager(this);
|
||||||
PluginManager.LoadPlugins(_settings.PluginSettings);
|
PluginManager.LoadPlugins(_settings.PluginSettings);
|
||||||
_mainVM = new MainViewModel(_settings);
|
_mainVM = new MainViewModel(_settings);
|
||||||
var window = new MainWindow(_settings, _mainVM);
|
_mainWindow = new MainWindow(_settings, _mainVM);
|
||||||
API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet);
|
API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet);
|
||||||
PluginManager.InitializePlugins(API);
|
PluginManager.InitializePlugins(API);
|
||||||
|
|
||||||
Current.MainWindow = window;
|
Current.MainWindow = _mainWindow;
|
||||||
Current.MainWindow.Title = Constant.ExeFileName;
|
Current.MainWindow.Title = Constant.ExeFileName;
|
||||||
|
|
||||||
// happlebao todo temp fix for instance code logic
|
// happlebao todo temp fix for instance code logic
|
||||||
@ -161,20 +162,40 @@ namespace PowerLauncher
|
|||||||
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
|
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()
|
public void OnSecondAppStarted()
|
||||||
{
|
{
|
||||||
Current.MainWindow.Visibility = Visibility.Visible;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,9 +16,10 @@ using System.Timers;
|
|||||||
using Microsoft.PowerLauncher.Telemetry;
|
using Microsoft.PowerLauncher.Telemetry;
|
||||||
using Microsoft.PowerToys.Telemetry;
|
using Microsoft.PowerToys.Telemetry;
|
||||||
|
|
||||||
|
|
||||||
namespace PowerLauncher
|
namespace PowerLauncher
|
||||||
{
|
{
|
||||||
public partial class MainWindow
|
public partial class MainWindow : IDisposable
|
||||||
{
|
{
|
||||||
|
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
@ -268,6 +269,8 @@ namespace PowerLauncher
|
|||||||
|
|
||||||
private const int millisecondsToWait = 100;
|
private const int millisecondsToWait = 100;
|
||||||
private static DateTime s_lastTimeOfTyping;
|
private static DateTime s_lastTimeOfTyping;
|
||||||
|
private bool disposedValue = false;
|
||||||
|
|
||||||
private string ListView_FirstItem(String input)
|
private string ListView_FirstItem(String input)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(input))
|
if (!string.IsNullOrEmpty(input))
|
||||||
@ -356,5 +359,34 @@ namespace PowerLauncher
|
|||||||
{
|
{
|
||||||
Hide();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user