HTML and CSS Reference
In-Depth Information
function performSuspend(e) {
WinJS.Utilities.query("#leftContainer h1")[0].innerText ="Suspended";
I have used the events provided through the Windows.UI.WebUI.WebUIApplication class,
and they neatly map to the life-cycle events. My example Metro app doesn't currently perform
any tasks that are affected by the application being suspended and resumed, but I want to show
you how to test for the events. To that end, I have added statements to the performResume and
performSuspend functions that change the value of h1 elements in the HTML document to indi-
cate when the suspending and resuming events are received.
Testing the Life-Cycle Events
The most important thing to remember when testing for the resuming and suspending events
is that you can't do it using the Visual Studio debugger, which disables these events so that
Windows doesn't suspend your application when the debugger breaks on an exception.
This is why I have used the h1 elements to indicate when the suspending and resuming
events are received. I can't use the JavaScript console or the debugger output because neither
is available.
I show you how to use trigger the life-cycle events manually in the sections that fol-
low, which means working without the debugger. There are some buttons that appear on the
Visual Studio toolbar to simulate the life-cycle events with the debugger, but I recommend you
use these with caution, because they generate simulated events that don't give you a complete
picture of how your app is treated by the operating system during its life cycle.
Activate the Application
To trigger the activated event, start the application by selecting Start Without Debugging from
the Visual Studio Debug menu. You can also start the app from the Start menu, either in the sim-
ulator or on your local machine. The important thing is not to start the app with the debugger.
Suspend the Application
The easiest way to suspend the application is to switch to the desktop by pressing Win + D. Open
the Task Manager, right-click the item for your Metro app, and select Go to Details from the
pop-up menu. The Task Manager will switch to the Details tab and select the WWAHost.exe pro-
cess that is responsible for running the app. After a few seconds, the value shown in the Status
column will change from Running to Suspended, which tells you that Windows has suspended
the app. The app will have been sent the suspending event, but we have no way to see that until
we resume it.
Search WWH ::

Custom Search