locked
Unregister background task

    Question

  • Hi, I'm facing a problem with the background tasks in debug mode. I use two background tasks to update the live tile of my app. One is Time triggered and the other is System triggered. Before I register them I use this

    foreach (var task in BackgroundTaskRegistration.AllTasks)
                    {
                        if (task.Value.Name == TASK_NAME)
                            task.Value.Unregister(true);                    
                    }

    to unregister any previous. Now in the Resume event I want to reload the main page and I use

    this.Frame.Navigate(this.GetType());
                this.Frame.BackStack.Clear();     
    and here the problem starts. When I debug the app, I put it in suspend mode and the in resume to call my resume event, but every time I see that my background tasks are doubled from 2 to 4 to 8 etc. Shouldn't they stay 2 since I unregister them? Thank you very much.

    Sunday, August 17, 2014 6:24 AM

All replies

  • Hi Giannisdolon,

    Your code seems right as the same as MSDN code sample.

    > but every time I see that my background tasks are doubled from 2 to 4 to 8 etc. Shouldn't they stay 2 since I unregister them?

    Did you check the background tasks before adding new background task? If the two tasks are still working, please don’t add them again in resume event. See more details from http://code.msdn.microsoft.com/Background-Task-Sample-9209ade9.

    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, August 18, 2014 9:20 AM
    Moderator
  • So, unregistering the task isn't enough do I have to cancel it as well. (sorry about the delay, I was away)
    Friday, August 22, 2014 8:01 PM
  • Hi giannisdolon,

    I think unregister the task is enough.

    Let's say we set a breakpoint in the foreach loop you mentioned in your question and see what are the registered background task, also you could monitor the background task list after you un-register specific tasks to see why 2,4,6 exist. Simply read from your code, it's ok.

    --James 


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, August 26, 2014 6:27 AM
    Moderator
  • I tried it and I get different id's after every resume. I also noticed that the resume method is also runs 2, 4, 8, 16 etc after every resume, so I'm thinking it has to do something with the Backstack but no sure what to do.
    Tuesday, August 26, 2014 8:28 PM