如何禁用UWP App暂停? [英] How to Disable UWP App Suspension?

查看:59
本文介绍了如何禁用UWP App暂停?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#开发仅在台式计算机上运行的Windows 10 UWP应用,目标平台版本为10.0.14393.0.由于业务需求,应用程序的生命周期必须像传统的Win32应用程序一样.

I am using C# to develop a UWP app for Windows 10 running only on desktop computers, targeting platform version 10.0.14393.0. Due to business requirements, the app lifecycle must behave like a traditional Win32 application.

因此,我遵循了

Therefore, I followed the recommendation from this article to request an ExtendedExecutionSession with ExtendedExecutionReason.Unspecified. I also configured Windows to never sleep and never hibernate.

不过,在极少数情况下,Windows会出于 SystemPolicy 原因撤消扩展执行会话,然后继续挂起UWP应用.

Still, on rare occasions, Windows will revoke the extended execution session with reason SystemPolicy and then proceed to suspend the UWP app.

两个问题:

  1. 如何获取有关导致Windows撤销扩展执行会话的原因的更多信息(系统日志或事件日志?)?
  2. 如何摆脱这些罕见的挂起情况,以便UWP应用程序生命周期的行为与Win32应用程序完全一样(也就是说,保持运行直到用户明确停止运行)?

谢谢!

推荐答案

ExtendedExecutionSession ExtendedExecutionReason.Unspecified 受制于对资源消耗的多重限制.由于您的测试设备没有电池,因此您的应用被暂停的最可能的原因是其高内存使用率.您可以尝试在内存消耗方面优化应用程序,并使用 Documentation建议使用> Memory Management API ,但这仍然不能保证您的应用永远不会被暂停.

ExtendedExecutionSession with ExtendedExecutionReason.Unspecified is a subject to multiple restrictions regarding resource consumption. Since your test device doesn't have a battery, then the most likely reason for your app getting suspended is its high memory use. You can try to optimize the app in terms of memory consumption and make use of Memory Management APIs as documentation suggests, but still this doesn't guarantee that your app will never get suspended.

如果您的应用程序是针对商业领域的,那么您可以考虑使用功能更强大的

If your app is aimed at business sector then you might consider using more powerful ExtendedExecutionForegroundSession instead of ExtendedExecutionSession. This would probably be the perfect solution for your problem. But it's a restricted capability, which means an app that utilizes it is not allowed to Windows Store - only to Windows Store for Business. You'd also need to manually declare the extendedExecutionUnconstrained capability in the manifest (see the Special and restricted capabilities section of documentation) to take advantage of the API.

或者,您可以使用可防止应用长时间暂停的黑客程序:

Alternatively you can use hacks that prevent app from getting suspended for long periods of time:

  1. 使用 应用程序服务 ,用于按照 pnp0a03 建议与Win32应用进行通信.

  1. Use of App services for communicating with Win32 apps as pnp0a03 suggested.

使用 背景媒体播放 ,用于在循环中无限次在后台播放无声音频样本(即使用户手动将其停止或另一个应用程序将其暂停以播放自己的背景音频,您的应用也可以对其进行跟踪并自动重新启动播放).

Use Background Media Playback for playing silent audio sample in the background infinitely in a loop (even if the user stops it manually or another app pauses it to play its own background audio, your app can trace it and automatically restart the playback).

这篇关于如何禁用UWP App暂停?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆