[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

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

View File

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

View File

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

View File

@@ -226,7 +226,11 @@ namespace Microsoft.Plugin.Uri
{
if (!_disposed && disposing)
{
Context.API.ThemeChanged -= OnThemeChanged;
if (Context != null && Context.API != null)
{
Context.API.ThemeChanged -= OnThemeChanged;
}
_disposed = true;
}
}

View File

@@ -113,7 +113,11 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
{
if (disposing)
{
Context.API.ThemeChanged -= OnThemeChanged;
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;
}