How to restart an app in UWP?
Asked Answered
J

3

6

Currently in my UWP application, I provide a way to change the app theme. But in order for the change to be effective, the user has to manually close the app and restart it. I'm looking for a way to do it automatically, ie, restart the app programmatically.

Is it even possible? thank you.

Jarry answered 16/9, 2016 at 18:24 Comment(0)
M
9

According to a recent blog post, there is a new API for this "from Build 16226 onwards, along with the corresponding SDK."

The new static RequestRestartAsync(String) method and overloads on CoreApplication provide the previously unavailable app restart magic, including the ability to pass arguments to the new instance.

Marotta answered 6/8, 2017 at 21:46 Comment(1)
I started using the new API when running in Fall Creators Update (or later) and it works well. For previous versions, I send "restart app" toast notification and then immediately exit with App.Current.Exit(). Toast makes it easy for the users to manually restart, since that is the intension.Marotta
Z
2

As far as I know there is no way for a UWP app to close itself so that means you cannot restart the app. Looks like you can close an app by using `App.Current.Exit()' but still no way to restart afterwards.

I would actually be looking at why do you need to restart when changing theme. With the way the theming systems is built it should be possible to change everything dynamically. But that might be food for a different question

Zetana answered 16/9, 2016 at 19:30 Comment(2)
If you want to close the app itself, you can try to use App.Current.Exit(), though that wouldn't restart it, just close.Tribromoethanol
I stand corrected. Didn't know you can close it. You couldn't in previous Store app versions. Thanks!Zetana
H
0

You can close the app but you can't restart it.

Window.Current.Close();
Hebe answered 6/8, 2017 at 17:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.