[英]How do I handle suspension of Windows 10 apps correctly in Visual C# or C++?
MSDN-Site仅具有适用于Windows 8 / 8.l Metro / Pseudo UWP应用程序的旧信息。 在此应用中,Microsoft提供了复杂的暂停帮助程序类,该类在Windows 10 UWP空白应用模板中不可用。 因此,我该如何处理Windows 10 UWP应用程序中的暂停。 我尚未找到有关如何处理此应用中的暂停的任何信息。
有人知道我该如何处理停权吗?
Visual Studio给出的默认模板中不存在您要查找的示例。 有一个项目来创建具有此功能的模板。 您可以在...找到这些模板。
https://github.com/Windows-XAML/Template10
这是模板10中有关暂停和恢复的代码
Resuming += (s, e) => { OnResuming(s, e); };
Suspending += async (s, e) =>
{
// one, global deferral
var deferral = e.SuspendingOperation.GetDeferral();
try
{
foreach (var service in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices))
{
// date the cache (which marks the date/time it was suspended)
service.FrameFacade.SetFrameState(CacheDateKey, DateTime.Now.ToString());
// call view model suspend (OnNavigatedfrom)
await service.SuspendingAsync();
}
// call system-level suspend
await OnSuspendingAsync(s, e);
}
catch { }
finally { deferral.Complete(); }
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.