locked
Background Task Progress Handler does not activate

    Question

  • I've written a background task in an Win 8 app I'm working on to periodically check for new items in feeds. The task works and if the app runs, successfully fires off it's completion handler. However, I cannot get the progression event handler to fire. I'm using a helper class to register the event/re-attach the handlers

    public static async void RegisterBackgroundTask(string taskName, string entryPoint, uint checkTime, BackgroundTaskCompletedEventHandler completionMethod, BackgroundTaskProgressEventHandler progressHandler = null)

    ....

    foreach (var task in BackgroundTaskRegistration.AllTasks) { if (task.Value.Name == taskName) { // Re-Register progress completion event handler. task.Value.Completed += completionMethod; task.Value.Progress += progressHandler; return; // The task is already registered, so no need to set again. }

    The progress task
    private async void OnBackgroundTaskProgress(IBackgroundTaskRegistration task, BackgroundTaskProgressEventArgs e)
    {
       uint progress = e.Progress;
       System.Diagnostics.Debug.WriteLine("Progress: " + progress");
    }

    And the method that calls the register/reattaching method:

    BackgroundTaskHelpers.RegisterBackgroundTask("TileUpdater", "NarrowCastBackgroundTasks.TileUpdater", checkTimeuint, OnBackgroundTaskComplete, OnBackgroundTaskProgress);

    I'm stumped. I've followed the Quickstart to the letter, and the completion handler fires off successfully. Any help would be appreciated!

    Thursday, March 6, 2014 11:47 AM

Answers

  • Sorry for double posting, but finally figured out the solution, and something that the Quickstart/documentation should really point out to save other people the headache:

    A background Task's progress event is called each time you set the task instance's progress value. I assumed the progress event was called at regular intervals.

    Hope this helps others in the future from days of bafflement.


    Tuesday, March 11, 2014 9:57 PM

All replies

  • Hi Bluezumbrellas..

    Try this.. This might help you..

    Go to the Package.appxmanifest from the Solution Explorer -> Click Declarations tab -> Then from Available Declarations, select Background Tasks & click Add -> Then give the Supported Task Types & give the name of your app in the Entry Point field.

    Thursday, March 6, 2014 4:39 PM
  • Thanks for the advice, but no luck unfortunately.

    The task is declared in the manifest already, and everything works perfectly EXCEPT the progress handler. The console log reads it as a BackgroundProgressHandler and I don't get an exception assigning the event. The registration method is in a class that's in a class library, and is static if that helps

    Thursday, March 6, 2014 5:19 PM
  • Sorry for double posting, but finally figured out the solution, and something that the Quickstart/documentation should really point out to save other people the headache:

    A background Task's progress event is called each time you set the task instance's progress value. I assumed the progress event was called at regular intervals.

    Hope this helps others in the future from days of bafflement.


    Tuesday, March 11, 2014 9:57 PM