0

我有一个 Windows Phone 8 项目,我希望在其中有一个响应 NetworkStateChange 系统触发器的后台任务。

我发现了这个问题:Windows Phone 8.1 Background Task - Can't Debug and won't fire,下载并重新实现了解决方案(http://1drv.ms/1qCPLMY),并在一些帮助下,结果很好。

我做了这个简单的任务:使用 Windows.ApplicationModel.Background;

namespace FlexCheck.Tasks
{

    public sealed class BackgroundTask : IBackgroundTask
    {
        BackgroundTaskDeferral _deferral = null;

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();
            _deferral.Complete();
        }

    }
}

为了编译它,我需​​要目标是 Windows Phone 8.1。但后来我无法从我的 Windows 8 项目中引用。

问题:我能以某种方式解决这个问题吗?或者是否有可以在 Windows phone 8 上使用的等效 IBackgroundTask?

4

1 回答 1

1

Windows Phone 8 中的后台代理无法对事件做出反应。它只是在计时器上运行的一段代码,仅此而已。切换到 WP 8.1 是唯一的一种解决方案。您可以尝试使用音频后台代理作为 hack,并在代码中手动检查网络状态,但这是违反规则的,通常不会通过商店认证。

于 2014-11-05T12:55:41.753 回答