question

zipswich avatar image
0 Votes"
zipswich asked ·

System.Exception: 'Invalid window handle' by CoreApplication.RequestRestartAsync("")

Could anyone shed some light on what may cause System.Exception: 'Invalid window handle' thrown by CoreApplication.RequestRestartAsync("")?

windows-uwp
· 3
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.

I used it without problems, so I wonder if the problem is related to the moment you call it. In which state is the app when you call RequestRestartAsync? On the UI thread or on another thread? It is running on a desktop or on other device? Which TargetPlatformVersion and TargetPlatformMinVersion?

1 Vote 1 ·

Thank you for looking into it. I should have posted the code snippet:

 await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
     async () => {
    
         try
         {
             AppRestartFailureReason arfr = await CoreApplication.RequestRestartAsync("");
             if (arfr == AppRestartFailureReason.NotInForeground
                 || arfr == AppRestartFailureReason.Other)
             {
                 Utility.LogMessageJsonAsync("Restarting failed: " + arfr);
             }
             else
             {
                 //do nothing
             }
         }
         catch (Exception ex)
         {
             Utility.LogMessageJsonExAsynch("Exception from await CoreApplication.RequestRestartAsync():", ex);
         }
     });

It was running on a desktop. I also should have mentioned this happens only occasionally. The UWP app targets 18632.

1 Vote 1 ·

Yep, I run above code within a blank uwp app, and it does not throw any exceptions, I could not reproduce your issue, could you mind share a demo that could reproduce this problem that will be better to find the reason.

0 Votes 0 ·

1 Answer

JackAnderson-3485 avatar image
0 Votes"
JackAnderson-3485 answered ·

A simple restart of the app should solve this.

·
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.