首页 文章

如何在Visual C#或C中正确处理Windows 10应用程序的暂停?

提问于
浏览
0

MSDN网站仅包含适用于Windows 8 / 8.l Metro / Pseudo UWP应用程序的旧信息 . 在这个应用程序中,Microsoft提供了一个复杂的暂停助手类,这在Windows 10 UWP Blank应用程序模板中不可用 . 那么我该如何处理Windows 10 UWP应用程序中的暂停 . 我还没有找到有关如何在此应用程序中处理暂停的任何信息 .

有谁知道如何处理暂停?

1 回答

  • 0

    您正在寻找的示例在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(); }
                };
    

相关问题