System.InvalidOperationException When Returning From Background

Nathan Sokalski 4,116 Reputation points
2020-02-12T02:16:29.853+00:00

I have a UWP app that uses the TileControl from the Windows Community Toolkit (Microsoft.Toolkit.Uwp.UI.Controls.TileControl), and I use a *.png file as the ImageSource. This seems to works fine, except when I leave & return to the app. It seems to only be a problem sometimes, but I'm not sure why. From what I can tell, it only causes a problem if I leave the app long enough to trigger the LeavingBackground event of the app. Here are the last few lines of output from the Immediate window:

App_LeavingBackground
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
App_UnhandledException
System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
at Microsoft.Toolkit.Uwp.UI.Controls.TileControl.<>c__DisplayClass47_0.b__0(LoadedImageSurface s, LoadedImageSourceLoadCompletedEventArgs e) System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
at Microsoft.Toolkit.Uwp.UI.Controls.TileControl.<>c__DisplayClass47_0.b__0(LoadedImageSurface s, LoadedImageSourceLoadCompletedEventArgs e)

There are multiple TileControl(s), and I am suspecting (although I am not the most knowledgeable about overlapping asynchronous and tasks) that the problem has something to do with loading the images at the same time. The ImageSource is specified directly in the XAML, and does not change, although the TileControl is part of a DataTemplate that is used multiple times. I have almost no experience debugging this kind of problem, so I'm not quite sure what to do next. Can somebody help me? Thanks.

Universal Windows Platform (UWP)
{count} votes