locked
BackgroundTask - Task not executing on app restart

    Question

  • I have few doubts regarding implementing BackgroundTask (with TimeTrigger - 15mins) for showing toast notification. Would be nice, if someone can explain the same. Assume that I register a BackgroundTask; my task will show notification when app is running/suspended, which is fine.

    If I close my app and come back again to the app. I can query the BackgroundTaskRegistration (on app start) which shows my previously registered task is there. But, I cannot see the toast notification in that case. Why? Do I need to do re-register the task again?

    Is that the expected behavior.

    Thanks.


    Sometimes, Difficult things are possible... www.cametoofar.com

    Thursday, February 13, 2014 1:14 PM

Answers

  • Hi,

    If you can register your background task successfully, you do not need re-register the task again.

    You can find out if the background task is already registered by iterating through the BackgroundTaskRegistration.AllTasks property. See Create and register a background task to get more information.

    15 minutes time interval is the standard for time triggered background tasks. You cannot set less than 15 minutes. If FreshnessTime is set to less than 15 minutes, an exception is thrown when attempting to register the background task. And you cannot always see notifications in your app, you can run a backgroundtask every 15 minutes, or when the user logons, or other system events. So if you register background for time triggered, you can only see notifications for 15 minutes interval.

    And you can see Guidelines and checklist for background tasks, the Introduction to Background Tasks white paper, and the Windows 8 app developer blog Being productive in the background – background tasks to get more information.

    Best Wishes!


    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. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; 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.


    Friday, February 14, 2014 2:35 AM

All replies

  • Hi,

    If you can register your background task successfully, you do not need re-register the task again.

    You can find out if the background task is already registered by iterating through the BackgroundTaskRegistration.AllTasks property. See Create and register a background task to get more information.

    15 minutes time interval is the standard for time triggered background tasks. You cannot set less than 15 minutes. If FreshnessTime is set to less than 15 minutes, an exception is thrown when attempting to register the background task. And you cannot always see notifications in your app, you can run a backgroundtask every 15 minutes, or when the user logons, or other system events. So if you register background for time triggered, you can only see notifications for 15 minutes interval.

    And you can see Guidelines and checklist for background tasks, the Introduction to Background Tasks white paper, and the Windows 8 app developer blog Being productive in the background – background tasks to get more information.

    Best Wishes!


    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. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; 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.


    Friday, February 14, 2014 2:35 AM
  • Well, I've gone through all those theoretical explanation in documents and links. What happens when the app is closed. Does It show any toast notification from the background task, that I've registered. Or do I need to rely on push notification for showing toast notification when the app is closed.

    Thanks.


    Sometimes, Difficult things are possible... www.cametoofar.com

    Monday, February 17, 2014 7:27 AM
  • Hi,

    If you successfully registered a background task in your app, the background task can also run when you close your app. You can show toast notification for time triggered background tasks or system events triggered background tasks. And 15 minutes time interval is the standard for time triggered background tasks. So as my first reply says, you cannot always see toast notification , only by every 15 minutes, or when the user logons, or other system events triggered. You can see Supporting your app with background tasks.

    Best Wishes!


    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. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; 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, February 18, 2014 6:13 AM
  • Thanks for the reply. I've few doubts related to the above response. Glad, if you can answer those too.

    1. What to do when a background task is cancelled, due to some reason (say, IdleTask state). Will that background task be executed again? If so, when? Or Do I need to re-register it again?

    2. In the MSDN sample: http://code.msdn.microsoft.com/windowsapps/Background-Task-Sample-9209ade9/sourcecode?fileId=43572&pathId=498327315, the background task (SampleBackgroundTask.cs) has ThreadPoolTimer inside the Run() method. If a TimeTrigger can run in every 15 minutes (as we configured), do we need a separate ThreadPoolTimer? Is the ThreadPoolTimer "specific to that sample only"?

    Thanks.


    Sometimes, Difficult things are possible... www.cametoofar.com

    Tuesday, February 18, 2014 4:36 PM
  • Hi,

    #Background tasks are meant to be short lived tasks that complete their work quickly and return from the task. This behavior is required due to strict CPU and network resource constraints on background tasks.To help enforce these constraints, the background task infrastructure detects background tasks that have become idle or that have stopped responding. If a background task has not utilized a minimum amount of CPU or network resource quota within a minimum amount of time then the background task is considered idle or hung.Then the background would be cancelled. If a background was be cancelled, it would not executed again. You should re-gister it again.

    #The ThreadPoolTimer is not relative to timetigger in background task. You can refer to the ThreadPoolTimer.CreatePeriodicTimerthe method is aim to creates a periodic timer and specifies a method to call after the periodic timer is complete. The periodic timer is complete when the timer has expired without being reactivated, and the final call to handler has finished. In the MSDN sample, it is a periodic timer to run PeriodicTimerCallback method which in order to handle a cancelled background task. If you want to you can refer to the link below:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh977059.aspx

    Best Wishes!


    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. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; 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.


    Wednesday, February 19, 2014 8:37 AM
  • Hello Anne,

    Thank you the detailed explanation. Now, its clear to me. My problem was I didn't requested for LockScreenAccess permission due to which the TimeTrigger was not triggered after 15 minutes.

    Phew! I think, MSDN documents needs to be little more detailed. I always feel, WinRT documentation, I feel that it is less than completed (just my thought!).

    Thanks for the help.


    Sometimes, Difficult things are possible... www.cametoofar.com

    Monday, February 24, 2014 12:55 PM