重新启动Windows UWP应用程序的所有可能方法是什么?



获得了一个使用ionic/angular/cordova堆栈构建的Windows UWP应用程序。我们从用户那里听到,由于某种原因,应用程序会自动关闭。从代码中,我们不做任何事情,比如关闭应用程序。在此实例期间,没有事件视图日志。这可能吗?

拥有像Sentry这样的错误监控库对于这些类型的问题将是非常好的。如果没有其他的错误细节,很难帮你解决问题。你最好的办法是获得应用程序的调试版本,然后打开检查器,看看你得到了什么错误。

注意到您的程序可能由于程序中未处理的错误而关闭,您可以尝试通过首先处理UnhandledException来避免程序关闭。

如果你需要重启功能,你可以使用CoreApplication.RequestRestartAsync。当ao被最小化或在后台时,系统会暂停应用程序。所以,当它调用RequestRestartAsync时,应用程序必须是可见的和前台的。

public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
this.UnhandledException += App_UnhandledException;
}
private void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{ 
//handle exception
e.Handled= true;
}

这是一个重新启动应用程序的示例代码。如果重新启动请求被拒绝,将发送toast通知用户手动重新启动。

AppRestartFailureReason result = await CoreApplication.RequestRestartAsync("Application Restart");
if (result == AppRestartFailureReason.NotInForeground
|| result == AppRestartFailureReason.Other)
{
// Requires Microsoft.Toolkit.Uwp.Notifications NuGet package version 7.0 or greater
new ToastContentBuilder()
.AddArgument("action", "viewConversation")
.AddArgument("conversationId", 9813)
.AddText("This UWP Restart failed")
.AddText("Please manually restart.")
.Show();
}