我有一个已发布在Windows/Microsoft Store的UWP应用程序,现在正在制作新的更新,我在我的应用程序中使用了Template10,它具有深色和浅色主题,在Windows 10移动版中,但为了使更改生效,用户必须手动关闭应用程序并重新启动。
是否有可能重新启动/重启我的应用程序?也就是说,单独/自动关闭应用程序并自动重新打开我的应用程序?
我有一个已发布在Windows/Microsoft Store的UWP应用程序,现在正在制作新的更新,我在我的应用程序中使用了Template10,它具有深色和浅色主题,在Windows 10移动版中,但为了使更改生效,用户必须手动关闭应用程序并重新启动。
是否有可能重新启动/重启我的应用程序?也就是说,单独/自动关闭应用程序并自动重新打开我的应用程序?
在Windows 10的"秋季创作者更新"(1709)中,我们引入了一个叫做RequestRestart()的新方法,以支持这种场景。您需要16299 SDK(或更高版本)才能访问此API。
https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.core.coreapplication#Methods_
以下是一篇博客/示例:
https://blogs.windows.com/buildingapps/2017/07/28/restart-app-programmatically/
RequestRestart()
选项,对吗? - Fernando SousaApp.Current.Exit();
退出。这使得用户可以轻松地重新启动应用程序。 - tiwahu您可以使用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();
}