简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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