0
votes

I have Windows Phone 8 project in which I would like to have a background tasks responding to the NetworkStateChange system Trigger.

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.

I've made this simple task : using 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. But then I can not reference from my Windows 8 project.

Question : Can I somehow get around this? Or is there an equivalent IBackgroundTask which can be used on Windows phone 8?

1
Is there a reason you target WP8 and not WP8.1? AFAIK all devices with WP8 can upgrade to 8.1. - Benjamin Diele
The reason is very simple: We haven't had time yet to lift it to 8.1. And since it is a large application it is not some thins done in 5 minuts :D - Jens Borrisholt
I think you can not get around this. Windows Phone 8 has Background Agents which seem much less useful than Background Tasks. - Benjamin Diele
Thank you @BenjaminDiele I'll have a look - Jens Borrisholt

1 Answers

1
votes

Background agents in Windows Phone 8 can't react to the events. It only a pieces of code that run on a timer, nothing more. Switching to WP 8.1 is the only one solution. 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.