locked
When Exactly do Running Threads get Suspended? RRS feed

  • Question

  • Hello there

    I have a Javascript based Windows store application which needs to respond to the notification that it is being suspended:

    WinJS.Application.addEventListener("checkpoint", onCLSuspend);

    function onCLSuspend(oEventArgs) {    
            oEventArgs.setPromise(mCLSuspendDo());
    }

    function mCLSuspendDo()

    {

      // Asynchronous function to save my data

    }

    At the point when onCLSuspend() is called, my application can be in the middle of processing asynchronous operations on both the foreground and background threads.  These threads are apparently stopped at the end of the current synchronous block of code when the app is suspended, and may get resumed from that point when the app is resumed. 

    My question is, when exactly are these threads stopped?  Are they stopped when mCLSuspendDo() is called, when mCLSuspendDo() is complete, or at some other point?  Will these other threads continue running whilst onCLSuspend() is running?

    Also, when exactly is the application suspended?  Is it suspended immediately when onCLSuspend is completed? 

    Any help would be appreciated.

    Geoff Olding

    Monday, October 8, 2012 9:42 AM

All replies

  • By default the app will will suspend as soon as the checkpoint event handler returns, but this can be deferred until a promise has completed:

    See the remarks at How to suspend an app :

    Note  If you need to do asynchronous work when your app is being suspended you will need to defer completion of suspend until after your work completes. You can use the setPromise method on the checkpoint event arg’s detail property to delay completion of suspend until after you complete the promise.

    Even with the deferral, the promise needs to complete before it times out in 5 seconds.

    --Rob

    Tuesday, October 9, 2012 3:13 AM
    Moderator
  • Thanks for your reply

    Does this mean that, whilst I am running my asynchronous processing in mCLSuspendDo(), that my existing application thread(s) will also still be running until mCLSuspendDo() has completed? -

    Regards

    Geoff Olding

    Tuesday, October 9, 2012 7:16 AM