在 Windows Store 应用 App 8.1 中触发暂停事件
Trigger suspension events in a Windows Store app App 8.1
WindowsStore应用App 8.1闲置一段时间后如何触发事件暂停?或者只是如何在闲置一段时间后将其暂停?
你不能强制挂起应用程序,你可以终止它,它会在一段时间后自动挂起..但是你可以通过在 app.xaml.cs 中订阅 OnSusbended 事件来触发:
this.Suspending += OnSuspending;
处理程序:
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//Use deferral for await calls :)
deferral.Complete();
}
顺便说一句,你可以用VS调试它,参考这个:
https://msdn.microsoft.com/en-us/library/hh974425.aspx
更新:
因为该应用程序是 Suspended
,您无法 运行 代码来检查,但您可以做的是:在应用程序暂停后将值保存到应用程序的设置中,假设它是:IsSuspended = 1
,并在应用程序启动 OnActivated 事件时使其成为 0
,这是在恢复后从 BackgroundTask 或前台应用程序进行检查的好方法。
WindowsStore应用App 8.1闲置一段时间后如何触发事件暂停?或者只是如何在闲置一段时间后将其暂停?
你不能强制挂起应用程序,你可以终止它,它会在一段时间后自动挂起..但是你可以通过在 app.xaml.cs 中订阅 OnSusbended 事件来触发:
this.Suspending += OnSuspending;
处理程序:
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//Use deferral for await calls :)
deferral.Complete();
}
顺便说一句,你可以用VS调试它,参考这个: https://msdn.microsoft.com/en-us/library/hh974425.aspx
更新:
因为该应用程序是 Suspended
,您无法 运行 代码来检查,但您可以做的是:在应用程序暂停后将值保存到应用程序的设置中,假设它是:IsSuspended = 1
,并在应用程序启动 OnActivated 事件时使其成为 0
,这是在恢复后从 BackgroundTask 或前台应用程序进行检查的好方法。