微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

了解Windows通用应用程序UWP中的扩展执行会话

我努力得到扩展的执行会话为我的Windows通用应用程序工作。

我试图达到的是以下情况。 用户希望通过蓝牙将手机与设备连接。 目前,无论何时屏幕closures或来电或用户最小化应用程序,连接失败,我们重新启动它恢复。 我想为这个正在进行的连接启用扩展执行,这样应用程序即使在最小化(挂起)时也能继续工作。

我想我需要的ExtendedExecutionReason.Unspecified ,因为它应该允许我的应用程序运行长达10分钟的暂停状态(这是绰绰有余我的目的)。 但是,连接总是似乎挂起失败(当我尝试改变我的应用程序的状态从debugging器使用VS的应用程序生命周期下拉列表中,我得到撤销ExtendedExecutionRevokedReason.SystemPolicy )。 我已经启用了我的应用程序的所有电池和后台权限,但仍然不好。

我的代码大致如下:

你如何保护自己免受内存消耗失控打破个人电脑?

有没有办法改变整个机器的GC行为?

.NET Thread.Sleep是否受到DST(或系统时间)更改的影响?

C#同步进程启动

Windows SDK安装失败

... (on begin connection) ClearExtendedExcecution(); displayRequest dr = new displayRequest(); var newSession = new ExtendedExecutionSession { Reason = ExtendedExecutionReason.Unspecified,Description = "Pair device" }; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); dr.RequestActive(); try { switch (result) { case ExtendedExecutionResult.Allowed: m_extendedExecutionSession = newSession; // DO WORK HERE await ConnectDeviceAsync(token); break; default: case ExtendedExecutionResult.Denied: // fallback to request screen active if extended execution fails,but still do work newSession.dispose(); await ConnectDeviceAsync(token); break; } } finally { dr.RequestRelease(); ClearExtendedExcecution(); } ... private async void SessionRevoked(object sender,ExtendedExecutionRevokedEventArgs args) { await CoreApplication.MainView.dispatcher.RunAsync(CoredispatcherPriority.normal,() => { switch (args.Reason) { case ExtendedExecutionRevokedReason.Resumed: Logger.Debug("Extended execution revoked due to returning to foreground."); break; case ExtendedExecutionRevokedReason.SystemPolicy: Logger.Debug("Extended execution revoked due to system policy."); break; } }); } private void ClearExtendedExcecution() { if (m_extendedExecutionSession == null) { return; } m_extendedExecutionSession.Revoked -= SessionRevoked; m_extendedExecutionSession.dispose(); m_extendedExecutionSession = null; }

任何关于我在做什么错误提示,扩展执行会话究竟是如何使用,或如何debugging应用程序的生命周期(没有得到系统策略撤销)将不胜感激。 谢谢!

对于.NET和Mono的跨平台线图库的build议

Windows证书存储

如何查看exe的SmartScreen声誉得分?

什么是一些免费或廉价的工具来search/索引文件系统(使用.Net)?

游标位置函数返回错误的值

在这种情况下,VS中的“Suspend”生命周期事件由于资源不足而模拟暂停,所以这就是为什么“SystemPolicy”的原因。

如果你在没有连接调试器的情况下运行你的应用程序,你最小化它(桌面)或切换到另一个应用程序(电话)执行将继续,但是(!),当你​​恢复你的应用程序会话被撤销的“恢复”原因,你必须通过调用RequestExtensionAsync()方法再次启动会话。

这种技术可以确保只要你需要,你的执行就会被激活。

这里是关于扩展执行的教程: https : //docs.microsoft.com/en-us/windows/uwp/launch-resume/run-minimized-with-extended-execution

以下是扩展执行的样本集: https : //github.com/Microsoft/Windows-universal-samples/tree/master/Samples/ExtendedExecution

您是正确的,最好在您的应用程序处于运行状态时使用未指定的扩展执行或位置跟踪,而处于暂停状态时不是保存数据。 对于您的具体情况,您听起来像是在尝试从Windows Phone继续与蓝牙设备进行通信。 根据蓝牙设备是BLE还是更早版本,GattCharacteristicNotificationTrigger或RfCommConnectionTrigger可能是更好的选择。 他们不要求你的应用程序不断在后台运行,而是在外设通信期间唤醒你的应用程序。 Kiran关于去年Build会议上不同类型的蓝牙触发器的概述是有用的,可以在这里找到: https : //channel9.msdn.com/Events/Build/2016/P460

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐