Skip to content

Commit 79a5b38

Browse files
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.
1 parent 0feca9c commit 79a5b38

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Core/TileControl/TileControl.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,21 @@ private async Task<bool> LoadImageBrushAsync(Uri uri)
173173
var loadCompletedSource = new TaskCompletionSource<bool>();
174174
_brushVisual = compositor.CreateSurfaceBrush(_imageSurface);
175175

176-
_imageSurface.LoadCompleted += (s, e) =>
176+
void LoadCompleted(LoadedImageSurface sender, LoadedImageSourceLoadCompletedEventArgs args)
177177
{
178-
if (e.Status == LoadedImageSourceLoadStatus.Success)
178+
_imageSurface.LoadCompleted -= LoadCompleted;
179+
180+
if (args.Status == LoadedImageSourceLoadStatus.Success)
179181
{
180182
loadCompletedSource.SetResult(true);
181183
}
182184
else
183185
{
184186
loadCompletedSource.SetException(new ArgumentException("Image loading failed."));
185187
}
186-
};
188+
}
189+
190+
_imageSurface.LoadCompleted += LoadCompleted;
187191

188192
await loadCompletedSource.Task;
189193
_imageSize = _imageSurface.DecodedPhysicalSize;

0 commit comments

Comments
 (0)