From bc22631340f89f8065c7433eff5259fd43ac6a43 Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Wed, 11 Nov 2020 13:18:15 -0800 Subject: [PATCH] adding disposed pattern --- src/modules/imageresizer/ui/App.xaml.cs | 27 ++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/modules/imageresizer/ui/App.xaml.cs b/src/modules/imageresizer/ui/App.xaml.cs index c95cffe381..029c2da138 100644 --- a/src/modules/imageresizer/ui/App.xaml.cs +++ b/src/modules/imageresizer/ui/App.xaml.cs @@ -13,11 +13,10 @@ using ImageResizer.Views; namespace ImageResizer { -#pragma warning disable CA1001 // Types that own disposable fields should be disposable - public partial class App : Application -#pragma warning restore CA1001 // Types that own disposable fields should be disposable + public partial class App : Application, IDisposable { private ThemeManager _themeManager; + private bool _isDisposed; static App() { @@ -45,5 +44,27 @@ namespace ImageResizer _ = NativeMethods.SendInput(1, inputs, NativeMethods.INPUT.Size); NativeMethods.SetForegroundWindow(hWnd); } + + protected virtual void Dispose(bool disposing) + { + if (!_isDisposed) + { + if (disposing) + { + _themeManager.Dispose(); + } + + // TODO: free unmanaged resources (unmanaged objects) and override finalizer + // TODO: set large fields to null + _isDisposed = true; + } + } + + public void Dispose() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(disposing: true); + GC.SuppressFinalize(this); + } } }