Freigeben über


oncheckpoint event

Occurs when receiving Process Lifetime Management (PLM) notification or when the checkpoint function is called.

Syntax

WinJS.Application.addEventListener("checkpoint", listenerName);
or
WinJS.Application.oncheckpoint = listenerName;

Event information

Synchronous No
Bubbles Yes
Cancelable Yes

 

Event handler parameters

  • eventInfo
    Type: CustomEvent**

    An object that contains information about the event. The detail property of this object includes the following subproperties:

    • type: "checkpoint"
    • setPromise: The Promise indicates that the event listener has pending asynchronous work. When the Promise is completed, the next handler is dispatched.

Remarks

The system suspends your app whenever the user switches to another app. The system resumes your app whenever the user switches back to it. When the system resumes your app, the content of your variables and data structures is the same as it was before the system suspended the app.

The system restores the app exactly where it left off, so that it appears to the user as if it's been running in the background. The system attempts to keep your app and its data in memory while it's suspended. However, if the system does not have the resources to keep your app in memory, the system terminates your app. When the user switches back to a suspended app that has been terminated, the app receives an activated event and should check whether its session state objects are defined. If the objects are defined, the app should load that data.

The system doesn't notify an app when it's terminated, so your app needs to save its application data and release exclusive resources and file handles when it's suspended, and it must restore them when the app is activated after termination.

You should also release any exclusive resources, like file handles at suspend, so that they can be used by other apps while your app is suspended.

For more information about the application lifecycle, see Guidelines for managing the app lifecycle.

Examples

The following code is based on the code used in the Visual StudioJavaScript project templates. It shows how to set the WinJS.Application.sessionState object in this event handler.

// This is an example of an object that is relevant to the state of your app.
var exampleObject = null;
var app = WinJS.Application;

app.onactivated = function (args) {
    if (args.detail.kind === activation.ActivationKind.launch) {
        if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
            // TODO: This application has been newly launched. Initialize
            // your application here.
            
            exampleObject = { exampleState: "running" }; 
        }
        args.setPromise(WinJS.UI.processAll());
    }
};

app.oncheckpoint = function (args) {
    // TODO: This application is about to be suspended. Save any state
    // that needs to persist across suspensions here. You might use the
    // WinJS.Application.sessionState object, which is automatically
    // saved and restored across suspension. If you need to complete an
    // asynchronous operation before your application is suspended, call
    // args.setPromise().

    // Set the sessionState object to the example object.
    app.sessionState = exampleObject;
};

 Windows.UI.WebUI.WebUIApplication.addEventListener("resuming", function (args) {
    if (WinJS.Application.sessionState)
        // Reset the example object to the saved state.
        exampleObject = WinJS.Application.sessionState;
}, false);

Requirements

Minimum WinJS version

WinJS 1.0

Namespace

WinJS.Application

See also

Tasks

How to suspend an app

Reference

WinJS.Application Namespace