【问题标题】:UWP application shutdown after 3 days 21 hoursUWP 应用程序在 3 天 21 小时后关闭
【发布时间】: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


【解决方案1】:

我最终选择了下面的idea。

  1. 下载并运行它。(免费应用程序“Restart on Crash”)
  2. 制作一个批处理文件以在崩溃时重新启动。(How to
  3. 使用“崩溃时重启”应用程序,设置如下。

这样的批处理文件。

@echo off
start shell:AppsFolder\2313d654-0c37-461f-ae1e-31336dde7fb3_sasbmbdd83txa!App

关闭UWP应用后,免费软件立即重启! 对我来说,已经足够了。

感谢 Stackoverflow 用户!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    • 2020-10-23
    • 2011-04-21
    • 2011-04-10
    • 2021-10-30
    相关资源
    最近更新 更多