locked
Background task for file sync or only sync when app is active?

    Question

  • I wonder what the recommended approach to file sync (ala skydrive) is recommended for Win8 apps?

    One possibility would be a background task that uploads/downloads files while the app is active as well as when its not active. This would certainly drain battery. But I wonder what for background tasks are there for if not sync features.

    Friday, May 18, 2012 10:44 AM

Answers

  • Hi Phil,

    So I drilled into that sucker and it does not sync or cache everything.  It does store some temporary files.  That said, I think you will find this blog appropriate for your questions:

    http://blogs.msdn.com/b/windowsappdev/archive/2012/05/16/being-productive-when-your-app-is-offscreen.aspx

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, May 22, 2012 6:06 PM
    Moderator
  • Nope, Suspend they continue to run.  Terminate they stop.

    See this section:

    After an app starts a background download operation, even if it gets suspended, these download operations continue in the background. The next time your app is resumed, you will receive the progress and completion callbacks of these download operations. If your app was terminated after being suspended, enumerating your download operations will restart previously queued background download operations. These next code examples show you how to enumerate your download operations in C# and JavaScript.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, May 23, 2012 1:25 PM
    Moderator

All replies

  • Hi,

    I would like to point out background file transfer is different from background tasks. Background file transfer "promotes smart power usage and prevents the issues that can arise when a connected app encounters events like unexpected app suspension, termination, or sudden network status changes.", as pointed out on http://msdn.microsoft.com/en-us/library/windows/apps/hh452979.aspx. So we don't need to worry about battery. Background tasks, on the other hand, are for small tasks that may occur repeatedly. Please refer to http://www.microsoft.com/en-us/download/details.aspx?id=27411 for more information.

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework

    Sunday, May 20, 2012 5:55 PM
    Moderator
  • Hi Phil,

    You are correct... doing file scrubs of your file directories, syncing tons of information etc... would be something that is not recommended because it would drain your battery.  Background tasks can be used for various other things however.  An example would be to wake up periodically and poll for information from a webservice for updates.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, May 21, 2012 11:44 AM
    Moderator
  • How and when does the SkyDrive app sync its content?
    Monday, May 21, 2012 11:55 AM
  • The SkyDrive app does not bring any data local.  When you view it in the file picker it goes up and gets the information via a filepicker extension.  Is that what you are asking Phil?


    Jeff Sanders (MSFT)

    Monday, May 21, 2012 12:06 PM
    Moderator
  • It does cache online files locally, I think. I have checked it myself in the appdata/local for the skydrive app.

    Question was: When does it sync the docs? Only on demand when the user requests it through a contract? And when does it upload new docs to the cloud? Does it query meta data (of files that exist on the cloud) in the background?


    • Edited by phil_ke Monday, May 21, 2012 12:11 PM
    Monday, May 21, 2012 12:10 PM
  • Wow!  I did not know that Phil.  Let me do some digging (later on today) and see if I can find out what it is doing and when.

    Jeff Sanders (MSFT)

    Monday, May 21, 2012 12:11 PM
    Moderator
  • Sure, the app should be working even when I am offline (in part at least) :)

    Thanks for your effort!

    Monday, May 21, 2012 12:14 PM
  • Hi Phil,

    So I drilled into that sucker and it does not sync or cache everything.  It does store some temporary files.  That said, I think you will find this blog appropriate for your questions:

    http://blogs.msdn.com/b/windowsappdev/archive/2012/05/16/being-productive-when-your-app-is-offscreen.aspx

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, May 22, 2012 6:06 PM
    Moderator
  • Thanks Jeff, that link was helpful. A good summary about whats possible. Now I need to find the right way to sync our data.

    I assume the BackgroundUploader and BackgroundDownloader are terminated once the app has been suspended by the system?

    Tuesday, May 22, 2012 6:29 PM
  • Nope, Suspend they continue to run.  Terminate they stop.

    See this section:

    After an app starts a background download operation, even if it gets suspended, these download operations continue in the background. The next time your app is resumed, you will receive the progress and completion callbacks of these download operations. If your app was terminated after being suspended, enumerating your download operations will restart previously queued background download operations. These next code examples show you how to enumerate your download operations in C# and JavaScript.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, May 23, 2012 1:25 PM
    Moderator