locked
[UWP]Background Task Doubt RRS feed

  • Question

  • Hi

    Does each invokation of background task creates new instance of Background task and calls run on that ? Or its the same task.

    Does calling background task frequently harms the performance? My requirement is to send some data on network on each button click and I am clicking button in my app at every 1 sec does background task make sense here ?If not what should be used. 

    Thanks!


    • Edited by Barry Wang Tuesday, August 30, 2016 8:23 AM title tag
    Monday, August 29, 2016 1:44 PM

Answers

  • Hello shushant arora,

    App service actually runs in a separate process when you call it. That is why we have this article:Convert an app service to run in the same process as its host app However it is also not used for being called time and time. And it is a kind of Backgroundtask. I've tried to see if any timer can work in appservice's OnRequestReceived but I failed to do it. So I'm afraid Appservice is also not an option. If you want to do this you may have to do it in your UI thread and use a timer. I don't think it is a good idea to think about send some data in backgroundtask in each second.

    Best regards,

    Barry


    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.

    • Proposed as answer by Barry Wang Wednesday, September 7, 2016 9:16 AM
    • Marked as answer by Barry Wang Thursday, September 8, 2016 6:00 AM
    Wednesday, August 31, 2016 9:55 AM

All replies

  • Hello,

    I don't think it make sense here for you to run your backgroundtak every 1 sec. Please see this guideline:

    Guidelines for background tasks

    "Background tasks should be lightweight to save battery life and provide a better user experience for foreground apps."

    And the only possible trigger for Timer is TimeTrigger which will be more than 15mins.You cannot use it to meet your requirement.

    And I don't know whether we can call it a new instance of Backgroundtask, but we can create more than one Backgroundtask in our app, they will be different task. I think for more details you can try test with some code.

    Best regards,

    Barry


    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.

    Tuesday, August 30, 2016 9:03 AM
  • Hi

    Can I call Appservice running in separate process every few seconds.Whats the cost of app service to my ui communication will it be time consuming?Is app service guranteed to run always ?

    Thanks

    Tuesday, August 30, 2016 1:15 PM
  • Hello shushant arora,

    App service actually runs in a separate process when you call it. That is why we have this article:Convert an app service to run in the same process as its host app However it is also not used for being called time and time. And it is a kind of Backgroundtask. I've tried to see if any timer can work in appservice's OnRequestReceived but I failed to do it. So I'm afraid Appservice is also not an option. If you want to do this you may have to do it in your UI thread and use a timer. I don't think it is a good idea to think about send some data in backgroundtask in each second.

    Best regards,

    Barry


    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.

    • Proposed as answer by Barry Wang Wednesday, September 7, 2016 9:16 AM
    • Marked as answer by Barry Wang Thursday, September 8, 2016 6:00 AM
    Wednesday, August 31, 2016 9:55 AM