locked
Universal Metro apps and background tasks

    Question

  • How do I call code from my Shared Project to run in the background of the Windows Phone project?

    To run code in the background on WP, I need to extract that to a new project and call that new project from my WP project. But to run the code I'd need to either:

    • Extract the logic into the background project (but then I lose the advantage of a Shared Project)
    • Duplicate the code

    Is there a way to make a Universal Windows (Phone) App that executes some business logic in the background, without duplicating the code or losing the advantage of a Shared Project?

    This is the code that is called when I put it in a seperate project. It is not called when I put it in either the WP project, or the shared project.

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Text;
    using Windows.ApplicationModel.Background;
    
    namespace WindowsPhoneProject
    {
        public sealed class BackgroundTask : IBackgroundTask
        {
            public void Run(IBackgroundTaskInstance taskInstance)
            {
                taskInstance.GetDeferral().Complete();
            }
        }
    }
    Friday, October 17, 2014 5:24 PM

Answers

  • Hi Benjamin,

    >Is there a way to make a Universal Windows (Phone) App that executes some business logic in the background, without duplicating the code or losing the advantage of a Shared Project?

    Yes, an easy way is to use Add as link feature. It can share code between projects without build portal class library. I think this feature will meet your requirement. Please see more information and how to use from Share Code with Add as Link.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, October 20, 2014 2:52 AM
    Moderator