简体   繁体   English

如何在UWP中重新启动应用程序?

[英]How to restart an app in UWP?

Currently in my UWP application, I provide a way to change the app theme. 目前在我的UWP应用程序中,我提供了一种更改应用程序主题的方法。 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. 谢谢。

According to a recent blog post , there is a new API for this "from Build 16226 onwards, along with the corresponding SDK." 根据最近的博客文章 ,有一个新的API“从Build 16226开始,以及相应的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. 新的静态RequestRestartAsync(String)方法和CoreApplication上的重载提供了以前不可用的应用程序重启魔术,包括将参数传递给新实例的能力。

As far as I know 我所知道的 there is no way for a UWP app to close itself UWP应用程序无法关闭自己 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. 看起来您可以使用`App.Current.Exit()'关闭应用程序,但之后仍无法重启。

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 但这可能是另一个问题的食物

您可以关闭应用程序,但无法重新启动它。

Window.Current.Close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM