locked
display a progress bar and statustext for long time background processing operation

    Question

  • Lets say I have a importFiles operation that could take a while.

    How would I implement such function with the possibility to monitor progress?

    I can think of 2 way:

    1. Have the process emit events to listeners
    2. Use a promise and callbacks for finish, error, and progress

    The thing is: the import is started on a different fragment page and then the app should switch to the overview page while the files are imported in the background. During the import it should show a progress bar and a text for the status message.

     

    Thursday, February 02, 2012 7:50 PM

Answers

  • Hi Phil,

    If your application is in the background, your application may indeed be suspended.  In that case you don't have to worry about updating UI!  Seriously though, background tasks do have the ability to report progress: http://www.microsoft.com/download/en/details.aspx?id=27411

    -Jeff


    Jeff Sanders (MSFT)

    • Marked as answer by Bob_Bao Tuesday, March 06, 2012 5:04 PM
    Tuesday, February 21, 2012 1:16 PM
    Moderator
  • Hey Phil,

    The easiest way to do this is number two: a Promise that reports progress. Switching fragments (navigating) doesn't break your Promises or unload any previously loaded JS files, which means that async operations will continue to run and the handler functions will still have their original scope. You could add some elements to you default.html to display status (like an absolutely positioned div that has a progress bar and an animated stick figure in a hard-hat); the progress function should be able to get and update that progress bar's width even if you've navigated a bunch of times.


    Senior Dev for Windows Phone Services


    Wednesday, February 22, 2012 12:21 AM

All replies

  • Hi Phil,

    Web Workers sound like a good fit for your situation:

    http://code.msdn.microsoft.com/windowsapps/Responsive-HTML5-f2dc48d2

    -Jeff


    Jeff Sanders (MSFT)
    Thursday, February 02, 2012 8:47 PM
    Moderator
  • The problem with Workers is, that they are suspended when the user moves the app in the background.


    Monday, February 20, 2012 7:47 AM
  • Hi Phil,

    If your application is in the background, your application may indeed be suspended.  In that case you don't have to worry about updating UI!  Seriously though, background tasks do have the ability to report progress: http://www.microsoft.com/download/en/details.aspx?id=27411

    -Jeff


    Jeff Sanders (MSFT)

    • Marked as answer by Bob_Bao Tuesday, March 06, 2012 5:04 PM
    Tuesday, February 21, 2012 1:16 PM
    Moderator
  • Thanks Jeff, I have read that paper already. Unfortunatly it clearly states, that we are not allowed to use background tasks for indexing operations.

    I am looking forward on how the new mail app in the upcoming beta does indexing of emails.

    Tuesday, February 21, 2012 1:22 PM
  • Hey Phil,

    The easiest way to do this is number two: a Promise that reports progress. Switching fragments (navigating) doesn't break your Promises or unload any previously loaded JS files, which means that async operations will continue to run and the handler functions will still have their original scope. You could add some elements to you default.html to display status (like an absolutely positioned div that has a progress bar and an animated stick figure in a hard-hat); the progress function should be able to get and update that progress bar's width even if you've navigated a bunch of times.


    Senior Dev for Windows Phone Services


    Wednesday, February 22, 2012 12:21 AM