From 79a5b38733143dc9a927f92683a5de3a1a384149 Mon Sep 17 00:00:00 2001 From: michael-hawker <24302614+michael-hawker@users.noreply.github.com> Date: Thu, 4 Mar 2021 15:27:06 -0800 Subject: [PATCH 1/2] Fixes #3629 TileControl crashes when moving monitors The LoadCompleted event was never unregistering and firing twice when reloaded across monitors causing an issue with the TaskCompletionSource. --- .../TileControl/TileControl.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs index 97bf7d111ec..a1663fd49ab 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs @@ -173,9 +173,11 @@ private async Task LoadImageBrushAsync(Uri uri) var loadCompletedSource = new TaskCompletionSource(); _brushVisual = compositor.CreateSurfaceBrush(_imageSurface); - _imageSurface.LoadCompleted += (s, e) => + void LoadCompleted(LoadedImageSurface sender, LoadedImageSourceLoadCompletedEventArgs args) { - if (e.Status == LoadedImageSourceLoadStatus.Success) + _imageSurface.LoadCompleted -= LoadCompleted; + + if (args.Status == LoadedImageSourceLoadStatus.Success) { loadCompletedSource.SetResult(true); } @@ -183,7 +185,9 @@ private async Task LoadImageBrushAsync(Uri uri) { loadCompletedSource.SetException(new ArgumentException("Image loading failed.")); } - }; + } + + _imageSurface.LoadCompleted += LoadCompleted; await loadCompletedSource.Task; _imageSize = _imageSurface.DecodedPhysicalSize; From 9549ff35b71ff3506363377653423760eb3ec1bd Mon Sep 17 00:00:00 2001 From: "Michael Hawker MSFT (XAML Llama)" <24302614+michael-hawker@users.noreply.github.com> Date: Mon, 8 Mar 2021 09:28:24 -0800 Subject: [PATCH 2/2] Update Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs Co-authored-by: Sergio Pedri --- .../TileControl/TileControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs index a1663fd49ab..e6337603864 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs @@ -175,7 +175,7 @@ private async Task LoadImageBrushAsync(Uri uri) void LoadCompleted(LoadedImageSurface sender, LoadedImageSourceLoadCompletedEventArgs args) { - _imageSurface.LoadCompleted -= LoadCompleted; + sender.LoadCompleted -= LoadCompleted; if (args.Status == LoadedImageSourceLoadStatus.Success) {