Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reboot/Restart an UWP app

Tags:

c#

windows-10

uwp

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?

like image 766
Fernando Sousa Avatar asked Oct 30 '17 18:10

Fernando Sousa


2 Answers

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://docs.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/

like image 51
Stefan Wick MSFT Avatar answered Oct 10 '22 12:10

Stefan Wick MSFT


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();  
            }  
like image 38
Luca Ziegler Avatar answered Oct 10 '22 11:10

Luca Ziegler