更改设置中联系人的访问权限会终止 UWP
应用程序。
当应用程序被系统关闭时,如何获取 terminating
或 terminated
事件?
更改设置中联系人的访问权限会终止 UWP
应用程序。
当应用程序被系统关闭时,如何获取 terminating
或 terminated
事件?
在App.xaml.cs文件的构造函数中订阅UnhandledException
和Suspending
事件。
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
this.UnhandledException += App_UnhandledException;
}
private async void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
// do your job
e.Handled = true;
}
Handled
属性为 true
,以防止应用程序崩溃和以不良方式关闭。 /// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
e.Handled = true;
? - Parsa Karami