Fernando Sousa
Fernando Sousa

Reputation: 265

Reboot/Restart an UWP app

I have an UWP app (published in Windows/Microsoft Store), and I am working in a new update, and I use Template10 in my app, that has dark and light theme, and in Windows 10 Mobile but for the change to be effective, the user has to manually close the app and restart it. Is there any possibility to restart/reboot my application? That is, to close the application alone/automatically and reopen my application automatically?

Upvotes: 16

Views: 6094

Answers (2)

Luca Ziegler
Luca Ziegler

Reputation: 4144

You can do this with CoreApplication.RequestRestart

 var result = await CoreApplication.RequestRestartAsync("Application Restart Programmatically ");  
  
            if (result == AppRestartFailureReason.NotInForeground ||  
                result == AppRestartFailureReason.RestartPending ||  
                result == AppRestartFailureReason.Other)  
            {  
                var msgBox = new MessageDialog("Restart Failed", result.ToString());  
                await msgBox.ShowAsync();  
            }  

Upvotes: 2

Stefan Wick  MSFT
Stefan Wick MSFT

Reputation: 13850

With the Fall Creators Update (1709) We have introduced a new method on CoreApplication called RequestRestart() that enables this scenario. You will need the 16299 SDK (or later) to access this API.

https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.core.coreapplication#Methods_

Here is a blog/sample:

https://blogs.windows.com/buildingapps/2017/07/28/restart-app-programmatically/

Upvotes: 17

Related Questions