prabu
prabu

Reputation: 217

WinJS application still running when suspended

I have a WinJS application that contains a timer object in it. I've read from the msdn docs that my application would be suspended after 5 seconds from the user navigating to another application, after which my app would stop running.

However, on testing the application in the suspended state, I've noticed that the timer keeps running. I've tried suspending the application by

  1. Clicking the "suspend" button from VS2012 debug window and
  2. Manually running my application, navigating to another application and waiting for a while(10mins) to get it suspended.

But in both cases, the timer keeps running. I expected it to stop at the point of suspension and resume with the same time when it is resumed, but instead it showed the elapsed time correctly.

I'd appreciate if anyone could explain this behavior. I'm running Windows 8 Release Preview.

Thanks.

Upvotes: 2

Views: 763

Answers (1)

Dominic Hopton
Dominic Hopton

Reputation: 7292

All timers are suspended when the app is suspended. I just verified it with this code:

function timerFired() {
    var container = document.getElementById("timeroutput");
    var content = document.createElement("div");
    content.textContent = Date.now();

    container.appendChild(content);
}

setInterval(timerFired, 1000);

When the app goes in the background, and suspends (which takes ~15 seconds before it's suspended), the text stops being appended to.

Note that:

  • While under the debugger the app is not automatically suspended, and you have to click the suspend button (as you say you are doing).
  • If you activate the application after suspension (e.g. click it, or switch back to it) the timer will execute immediately if the time it's been suspended is longer than the timer interval
  • if you are playing background audio correctly, then your timer will still run because you don't get suspended while you are playing background audio

Upvotes: 6

Related Questions