From f318a4f92a9b3b7941436ee429d492e3c9dbccd2 Mon Sep 17 00:00:00 2001 From: Bastian Schmidt Date: Fri, 23 Oct 2020 08:41:20 +0200 Subject: [PATCH] (GH-3944) Use BeginInvoke to prevent deadlocks in multithreaded cases --- src/MahApps.Metro/Behaviors/WindowsSettingBehavior.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MahApps.Metro/Behaviors/WindowsSettingBehavior.cs b/src/MahApps.Metro/Behaviors/WindowsSettingBehavior.cs index b599094835..4580d35a4a 100644 --- a/src/MahApps.Metro/Behaviors/WindowsSettingBehavior.cs +++ b/src/MahApps.Metro/Behaviors/WindowsSettingBehavior.cs @@ -47,7 +47,7 @@ private void AssociatedObject_SourceInitialized(object sender, EventArgs e) window.Closed += this.AssociatedObject_Closed; // This operation must be thread safe - Application.Current?.Invoke(() => Application.Current.SessionEnding += this.CurrentApplicationSessionEnding); + Application.Current?.BeginInvoke(() => Application.Current.SessionEnding += this.CurrentApplicationSessionEnding); } private void AssociatedObject_Closing(object sender, System.ComponentModel.CancelEventArgs e) @@ -93,7 +93,7 @@ private void CleanUp(string fromWhere) window.SourceInitialized -= this.AssociatedObject_SourceInitialized; // This operation must be thread safe - Application.Current?.Invoke(() => Application.Current.SessionEnding -= this.CurrentApplicationSessionEnding); + Application.Current?.BeginInvoke(() => Application.Current.SessionEnding -= this.CurrentApplicationSessionEnding); } #pragma warning disable 618