簡體   English   中英

如何在Visual C#或C ++中正確處理Windows 10應用程序的暫停?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM