简体   繁体   English

Windows Phone 8 中的后台任务

[英]Background task in Windows Phone 8

I have Windows Phone 8 project in which I would like to have a background tasks responding to the NetworkStateChange system Trigger.我有一个 Windows Phone 8 项目,我希望在其中有一个响应 NetworkStateChange 系统触发器的后台任务。

I've found this so QUESTION : Windows Phone 8.1 Background Task - Can't Debug and won't fire , downloaded and re-implemented the solution ( http://1drv.ms/1qCPLMY ), and with a little help, that worked out fine.我发现了这个问题: Windows Phone 8.1 后台任务 - 无法调试,不会触发,下载并重新实施解决方案( http://1drv.ms/1qCPLMY ),并在一些帮助下效果很好。

I've made this simple task : using Windows.ApplicationModel.Background;我做了这个简单的任务:使用 Windows.ApplicationModel.Background;

namespace FlexCheck.Tasks
{

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

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

    }
}

In order for this to compile I need target to be Windows Phone 8.1.为了编译这个,我需要目标是 Windows Phone 8.1。 But then I can not reference from my Windows 8 project.但是后来我无法从我的 Windows 8 项目中引用。

Question : Can I somehow get around this?问题:我能以某种方式解决这个问题吗? Or is there an equivalent IBackgroundTask which can be used on Windows phone 8?或者是否有可以在 Windows phone 8 上使用的等效 IBackgroundTask?

Background agents in Windows Phone 8 can't react to the events. Windows Phone 8 中的后台代理无法对事件做出反应。 It only a pieces of code that run on a timer, nothing more.它只是在计时器上运行的一段代码,仅此而已。 Switching to WP 8.1 is the only one solution.切换到 WP 8.1 是唯一的解决方案。 You can try an Audio Background agent as a hack and do some checks of the network state manually in the code, but this is a rule breaker and usually it won't pass the store certification.您可以尝试使用Audio Background 代理作为 hack,并在代码中手动检查网络状态,但这是违反规则的,通常不会通过商店认证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM