From 52330c8528342008eb67dd48cfdeaca546dfcf92 Mon Sep 17 00:00:00 2001 From: Luis von der Eltz Date: Sat, 13 Feb 2021 15:05:04 +0100 Subject: [PATCH] Correctly dispose manager upon application lifetime exit --- .../AppBuilderExtensions.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/DesktopNotifications.Avalonia/AppBuilderExtensions.cs b/DesktopNotifications.Avalonia/AppBuilderExtensions.cs index a793222..be5dc84 100644 --- a/DesktopNotifications.Avalonia/AppBuilderExtensions.cs +++ b/DesktopNotifications.Avalonia/AppBuilderExtensions.cs @@ -1,5 +1,6 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Platform; using DesktopNotifications.FreeDesktop; using DesktopNotifications.Windows; @@ -47,6 +48,17 @@ namespace DesktopNotifications.Avalonia //TODO Any better way of doing this? manager.Initialize().GetAwaiter().GetResult(); + builder.AfterSetup(b => + { + if (b.Instance.ApplicationLifetime is IControlledApplicationLifetime lifetime) + { + lifetime.Exit += (s, e) => + { + manager.Dispose(); + }; + } + }); + AvaloniaLocator.CurrentMutable.Bind().ToConstant(manager); return builder;