Tablet enters the sleep mode


  • Hi,

    I execute a long running operation in my Windows App (synchronizing a database using web services). Sometimes it runs so long that the tablet enters the sleep mode. I'm not sure what event the app receives: terminated or suspended? Also, how to deal with this kind of situations? I'd like to run the operation until it's finished regardless of the device entering the sleep mode.

    I can see two solutions:

    1. Temporarily prevent the device from entering the sleep mode (how to do that with WinRT?)

    2. Continue the operation even if the device is in the sleep mode. I was thinking about using a background task (IBackgroundTask and BackgroundTaskBuilder) but it is not suitable for my scenario as the operation is long running and computationally intensive. The background task is good to execute small pieces of code as it has limited amount of system resources.

    Any suggestions?



    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Thursday, April 3, 2014 6:31 PM

All replies

  • Intensive background computations aren't suitable for Windows Store apps. If that's the primary goal of the app it would be much better off as a desktop app.

    You can't universally keep the app alive: you can prevent the idling off for scenarios like playing a video (see How to keep the display on during audio/video playback), but the user can still switch away and the app will suspend.

    For what you describe, the main option will be to run while the app is in the foreground and pause when the app suspends. You may be able to trickle some through in a background task, but as you note this won't work for intensive computations or large amounts of data.

    If you can extract the data you need to upload to an isolated file you can upload that whole file in the background with a the background transfer classes (see Transferring data in the background) and then have the service on the other end crack the file and add it to your database.

    Thursday, April 3, 2014 7:19 PM
  • The lengthy operation I'm referring to is a synchronization process between the tablet and a remote database. I'm using a bunch of web services to send data to the database and also download some data. It's not as simple as compressing everything into a single file and sending it to the server as I have to exchange data with multiple web services.

    The synchronization process is not the primary goal of the app. Quite opposite - the user works with the app and then from time to time (maybe once a week) synchronizes data. The application is well-suited to be a Windows Store app because of the touch support and working in different orientations (portrait and landscape). The only problem is that sometimes during synchronization the device enters the sleep mode.

    I just thought the Windows Store apps would have an out-of-the-box solution to deal with such basic scenarios as a device entering the sleep mode. From your post it seems that they don't. Thanks for your suggestions though.


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Thursday, April 3, 2014 7:58 PM
  • I have another idea: how about I would somehow read the sleep mode settings on the tablet. This way I would approximately know if the long running operation would enter the sleep mode.

    Is it possible (and if so, how) to read sleep mode information using Windows Runtime?



    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Friday, April 11, 2014 3:21 PM
  • That would be problematic too - there's no guarantee that the user hasn't just pulled the power cable and entered a different power plan with different sleep settings, or that the user just started a sleep of the system.

    I've had a similar problem where my data is from various web sources.

    I took it right to the cloud.  When my client detects that it needs a sync (or the user requests one), it contacts the cloud, starts a sync from there and then polls for a job completion periodically.  Right now, 1 VM on Azure can handle about 50 client jobs due to the nature of the data, sites and length of the data 'compiling' job.

    Darin R.

    Friday, April 11, 2014 10:02 PM
  • The cloud would be a perfect solution. There is only one caveat: it costs money. That's why it's out of consideration for me at this moment. I know that reading sleep mode settings is less that ideal but it's better than just keep fingers crossed.

    I could not find any information in MSDN about reading sleep mode settings using Windows Runtime. Does anybody know how to do that?

    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Monday, April 14, 2014 2:09 PM