[PTRun] Fix crash when shutting Windows down (#13401)

This commit is contained in:
Jaime Bernardo
2021-09-23 18:09:38 +01:00
committed by GitHub
parent 64ecb553e4
commit d7098e87ee

View File

@@ -40,6 +40,9 @@ namespace PowerLauncher
private StringMatcher _stringMatcher; private StringMatcher _stringMatcher;
private SettingsReader _settingsReader; private SettingsReader _settingsReader;
// To prevent two disposals running at the same time.
private static readonly object _disposingLock = new object();
[STAThread] [STAThread]
public static void Main() public static void Main()
{ {
@@ -238,33 +241,44 @@ namespace PowerLauncher
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (!_disposed) // Prevent two disposes at the same time.
lock (_disposingLock)
{ {
Stopwatch.Normal("App.OnExit - Exit cost", () => if (!disposing)
{ {
Log.Info("Start PowerToys Run Exit---------------------------------------------------- ", GetType()); return;
if (disposing) }
{
if (_themeManager != null)
{
_themeManager.ThemeChanged -= OnThemeChanged;
}
API?.SaveAppAllSettings(); if (_disposed)
PluginManager.Dispose(); {
_mainWindow?.Dispose(); return;
API?.Dispose(); }
_mainVM?.Dispose();
_themeManager?.Dispose(); _disposed = true;
_disposed = true; }
Stopwatch.Normal("App.OnExit - Exit cost", () =>
{
Log.Info("Start PowerToys Run Exit---------------------------------------------------- ", GetType());
if (disposing)
{
if (_themeManager != null)
{
_themeManager.ThemeChanged -= OnThemeChanged;
} }
// TODO: free unmanaged resources (unmanaged objects) and override finalizer API?.SaveAppAllSettings();
// TODO: set large fields to null PluginManager.Dispose();
_disposed = true; _mainWindow?.Dispose();
Log.Info("End PowerToys Run Exit ---------------------------------------------------- ", GetType()); API?.Dispose();
}); _mainVM?.Dispose();
} _themeManager?.Dispose();
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
Log.Info("End PowerToys Run Exit ---------------------------------------------------- ", GetType());
});
} }
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources