[Run-Plugin][Program] Fix null reference exception on Dispose (#11785)

This commit is contained in:
Mykhailo Pylyp
2021-06-18 13:40:10 +03:00
committed by GitHub
parent c953f10c21
commit f662c062d2
7 changed files with 28 additions and 8 deletions

View File

@@ -170,8 +170,12 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
if (!_disposed)
{
if (disposing)
{
if (_context != null && _context.API != null)
{
_context.API.ThemeChanged -= OnThemeChanged;
}
_disposed = true;
}
}

View File

@@ -133,8 +133,12 @@ namespace Microsoft.Plugin.Folder
if (!_disposed)
{
if (disposing)
{
if (_context != null && _context.API != null)
{
_context.API.ThemeChanged -= OnThemeChanged;
}
_disposed = true;
}
}

View File

@@ -209,9 +209,13 @@ namespace Microsoft.Plugin.Program
if (!_disposed)
{
if (disposing)
{
if (_context != null && _context.API != null)
{
_context.API.ThemeChanged -= OnThemeChanged;
_win32ProgramRepositoryHelper.Dispose();
}
_win32ProgramRepositoryHelper?.Dispose();
_disposed = true;
}
}

View File

@@ -225,8 +225,12 @@ namespace Microsoft.Plugin.Uri
protected virtual void Dispose(bool disposing)
{
if (!_disposed && disposing)
{
if (Context != null && Context.API != null)
{
Context.API.ThemeChanged -= OnThemeChanged;
}
_disposed = true;
}
}

View File

@@ -112,8 +112,12 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
if (!_disposed)
{
if (disposing)
{
if (Context != null && Context.API != null)
{
Context.API.ThemeChanged -= OnThemeChanged;
}
_disposed = true;
}
}

View File

@@ -154,7 +154,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry
return;
}
if (!(_context is null))
if (_context != null && _context.API != null)
{
_context.API.ThemeChanged -= OnThemeChanged;
}

View File

@@ -169,7 +169,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
return;
}
if (!(_context is null))
if (_context != null && _context.API != null)
{
_context.API.ThemeChanged -= OnThemeChanged;
}