locked
Usage of BackgroundTask and Task

    Question

  • Hi

     

    I've have written a windows store app(myAPP) that "processes" a input file and produces a output.  The processing stage can take up to 5 minutes to perform.

     

    I am searching a design pattern that  can handle the following  functionality:

     

    1. myAPP is visible. Upon starting the processing stage, and during processing stage,, a progress indicator should be updated.
    2. myAPP is visible. User shall be able to "Cancel" the processing stage.
    3. User shall be able to shift to another application during processing stage and the processing stage will not be interrupted.
    4. myAPP is not visible. When the processing stage are finished a message shall be sent to the user and data saved.
    5. myAPP goes visible. When user restores my application during process stage, progress indicator should be updated.
    6. myAPP goes visible and 4 have occurred data should be loaded.

     

     

    I think that using BackgroundTask and Task,, can do the trick,, is there a established elegant way to do this?

     

     Can  anyone  give a good example.

     

    //regards

    //lg


    Lasse

    Monday, February 17, 2014 1:32 PM

All replies

  • Hi Lasse,

    You can use background tasks to provide functionality when your app is suspended or not running. Task can only be executed while the app is alive. For your requirement, I think BackgroundTask is much more suitable.

    More information please read: Supporting your app with background tasks

    --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, February 18, 2014 7:55 AM
    Moderator
  • Yes,, I am aware about the Background Task. I was looking for a example how to use it to meet my requirements. All that I have found on internet,, is to simplified for my purpose,, I think *smile*

    lg

    Tuesday, February 18, 2014 9:02 AM
  • i dont think the scenario you described can be done with a background task. Background tasks are limited in their CPU usage while running the background task for 5 minutes would go over this.

    Another problem is that you cant start a background tasks manually. you have triggers for this. like a time trigger but then it gets trigged at most once in the 15 minute while you still dont know when it will be triggered. ALthough this can be solved with raw push notifications.

    I think you have to come up with another solution. like is it possible to offload the operation to a cloud server?


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Tuesday, February 18, 2014 10:57 AM
  • Hi

    Pushing it to the cloud requires Interntet access,,, it was not my intention to require internet access for this application to work. I have to think about that solution.

    What happens if I do something like this:

            private void OnSuspending(object sender, SuspendingEventArgs e)
            {
                var deferral = e.SuspendingOperation.GetDeferral();
                await LongWorkThreadFinnished();
    SaveData()

                deferral.Complete();
            }

    Will this stop myApp from turning over the screen to the App requestion it,, and what happens when myApp reports Progress?


    lg

    Wednesday, February 19, 2014 7:34 AM
  • its gives you a few seconds (i thought 5 seconds) to save the last stuff before suspending. if not complete within this timeframe windows will kill you app

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Wednesday, February 19, 2014 9:01 AM
  • Ok. 

    So,, the option left if I dont have a internet connection.....

    - suspend my operation in such a way that it can be continued when my application resumes.

    This will not give the same user experience as destop applications gives,, where I often moves long running application into the "backgrouond" to be able to do other work.

    Expecting the same behavior in this respect,,,,,  between Store Apps and Desktop Apps,,,, is maby to wish for to much?? 

    Thanks for your support in this discussion.

    . 


    lg

    Wednesday, February 19, 2014 10:37 AM
  • its the option you got left yes; store apps are also targetting low powered devices where running such operation can drain the performance (battery) of the device too much.

    there is an other option; you have maintaince tasks. they can only run when the device is powered by AC and not by a battery. Those tasks are not limited with cpu usage


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Wednesday, February 19, 2014 10:42 AM
  • Hello,

    is the last answer true? Can i use a sort of timer to do things every few seconds for an unlimited time? Like it ist in Desktop apps?

    I mean when i have the Desktop or other apps in the foreground.

    Regards,
    Markus
    • Edited by Markus222 Wednesday, May 13, 2015 12:00 PM
    Wednesday, May 13, 2015 11:29 AM