【发布时间】:2017-12-13 05:07:07
【问题描述】:
我开发了一个带有传感器的监控系统。该应用程序必须运行 365 天,24 小时。
现在,我正在测试长期运行的应用程序。为了防止暂停,我写了这个。
<Capabilities>
<Capability Name="internetClient" />
<!--<rescap:Capability Name="runFullTrust" />-->
<rescap:Capability Name="extendedBackgroundTaskTime" />
<rescap:Capability Name="extendedExecutionUnconstrained" />
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
我也添加了这段代码。
Window.Current.CoreWindow.Activated -= CoreWindow_OnActivated;
Window.Current.CoreWindow.Activated += CoreWindow_OnActivated;
private void CoreWindow_OnActivated(CoreWindow sender, WindowActivatedEventArgs args)
{
// This seems to be the last chance we get to enable extended execution when going to the background.
// Trying this on OnVisibilityChanged, OnEnteredBackground, or OnSuspending is too late.
if ((null != args) && (CoreWindowActivationState.Deactivated == args.WindowActivationState))
{
ExtendedExecutionManager.Instance.BeginExtendedExecutionIfNeeded();
}
}
在第一次测试中,我的应用程序可以运行 3 天 21 小时。但突然间,它已经关闭,没有任何错误,也没有任何事件查看器日志。
这是 UWP 应用的限制吗??
应用程序安装为旁加载包。
更新 1:
当我制作侧载应用程序时,我检查了这个。但 Eventviewer 没有异常记录。有没有办法知道UWP应用崩溃日志?
更新 2
我尝试测试小型 UWP 应用程序并故意抛出异常。 使用,没有旁加载包中的 PDB 文件,EventViewer 会捕获“应用程序错误”。但是我的应用程序在 eventViewer 上没有任何消息就崩溃了...
我想说为什么......但是没有人可以回答...... 请给我更多的cmets。
要使用 WPF 重新构建,这是不可能的,需要 6 个月!
(第一个错误是侧载中的 PDB 文件。最后一个错误是没有 PDB)
【问题讨论】:
-
我认为创建用于监控目的的 UWP 应用程序似乎不是最好的解决方案,因为 UWP 生命周期的设计考虑到用户将切换黑白应用程序并且应用程序的执行需要暂停了一段时间。我建议为您想要实现的最终目标创建一个 Windows 服务,因为您不需要编写任何代码来使其处于活动状态,它会一直运行到您的系统启动并运行。
标签: uwp