Skip to main content
BackgroundExecutionManager class

Applies to Windows and Windows Phone

Provides methods that let an app ask to be added to the lock screen's apps list or query its current access to background activity and badge updates on the lock screen.

Syntax


var backgroundExecutionManager = Windows.ApplicationModel.Background.BackgroundExecutionManager;

public static class BackgroundExecutionManager

Public NotInheritable Class BackgroundExecutionManager

public ref class BackgroundExecutionManager abstract sealed 

Attributes

[ Version(0x06020000)]

Members

The BackgroundExecutionManager class has these types of members:

Methods

The BackgroundExecutionManager class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
GetAccessStatus Gets the ability of the calling lock screen app to perform background activity and update its badge.
GetAccessStatus(String) Gets the ability of a specific lock screen app to perform background activity and update its badge.
RemoveAccess Removes the calling app from the lock screen's apps list.
RemoveAccess(String) Removes a specific app from the lock screen's apps list.
RequestAccessAsync On Windows, this method presents the user with a dialog box that requests that an app be added to the lock screen. On Windows Phone, this method does not prompt the user, but must be called before registering any background tasks.
RequestAccessAsync(String) On Windows, this method presents the user with a dialog box that requests that an app be added to the lock screen. On Windows Phone, this method does not prompt the user, but must be called before registering any background tasks.

 

Remarks

Because apps with a presence on the lock screen are allowed to run some tasks in the background, certain classes of apps will require the access gained through this class in order to execute their core scenarios.

For a full sample demonstrating the use of this class, see the Lock Screen Sample on the Windows Dev Center.

Examples

This example shows the use of this class to add an app to the lock screen and grant it the ability to perform background tasks.


var Background = Windows.ApplicationModel.Background;

var promise = Background.BackgroundExecutionManager.requestAccessAsync().then(
    function(result) {
        switch (result) {
        case Background.BackgroundAccessStatus.denied:
            // Disabled by the user. 
            break;

        case Background.BackgroundAccessStatus.allowedWithAlwaysOnRealTimeConnectivity:
            // Added to list of background apps.
            // Set up background tasks; can use the network connectivity broker.
            break;

        case Background.BackgroundAccessStatus.allowedMayUseActiveRealTimeConnectivity:
            // Added to list of background apps.
            // Set up background tasks; cannot use the network connectivity broker.
            break;

        case Background.BackgroundAccessStatus.unspecified:
            // The user didn't explicitly disable or enable. 
            break;
        }
    });

Removing an app from the lock screen.


var Background = Windows.ApplicationModel.Background;
Background.BackgroundExecutionManager.removeAccess();

This example shows how to query for an app's lock screen state.


var Background = Windows.ApplicationModel.Background;

var result = Background.BackgroundApplications.getAccessStatus();
switch (result) {
case Background.BackgroundAccessStatus.denied:
    // Disabled by the user.
    // Cannot display on the lock screen or set up background tasks.
    break;

case Background.BackgroundAccessStatus.allowedWithAlwaysOnRealTimeConnectivity:
    // Added to list of background applications.
    // Can display on the lock screen.
    // Can set up background tasks and use the network connectivity broker.
    break;

case Background.BackgroundAccessStatus.allowedMayUseActiveRealTimeConnectivity:
    // Added to list of background applications.
    // Can display on the lock screen.
    // Can set up background tasks but cannot use the network connectivity broker.
    break;

case Background.BackgroundAccessStatus.unspecified:
    // The user didn't explicitly disable or enable.
    break;
}

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.ApplicationModel.Background
Windows::ApplicationModel::Background [C++]

Metadata

Windows.winmd

See also

Lock screen apps sample