question

njsokalski avatar image
0 Votes"
njsokalski asked ·

System.InvalidOperationException When Returning From Background

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.b0(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.cDisplayClass47_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.

uwpuwp-xaml
· 6
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Does this happen randomly? Could you please provide a reproduce sample to use to check this behavior? And it would be better to tell us the detailed steps to reproduce this issue.

0 Votes 0 · ·

After a little bit more experimentation, I have been able to identify a little bit more about when it happens. It only seems to happen if I switch to and stay in other apps long enough (I don't know exactly how long "long enough" is, but it is longer than a couple seconds). The lockup/Exception happens immediately after switching back to the app (clicking the button on the taskbar), even before I try to click or do anything in the app. Because the Exception happens before I attempt to do anything (at least that I am aware of), I am guessing, based on the fact that the Exception mentions methods related to loading the ImageSource of the TileControl, that it is trying to reload the ImageSource even though it is already loaded (unless it is getting unloaded when the app goes into the background, maybe it is, because like I said, I have little experience with this kind of problem). Could this be (or be related to) the problem? If it is, what can I do to fix it? If not, what could it be?

0 Votes 0 · ·

So could you please share a sample about this? And you could also share the detailed steps as well.

0 Votes 0 · ·
Show more comments

Any updates about your issue?

0 Votes 0 · ·

0 Answers