Jens Borrisholt
Jens Borrisholt

Reputation: 6402

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.

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?

Upvotes: 0

Views: 356

Answers (1)

crea7or
crea7or

Reputation: 4490

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.

Upvotes: 1

Related Questions