Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

BackgroundExecutionManager.RequestAccessAsync | requestAccessAsync methods

Requests that the app be permitted to run background tasks.

Overload list

MethodDescription
RequestAccessAsync() Requests that the app be permitted to run background tasks.
RequestAccessAsync(String) Requests that the app be permitted to run background tasks.

Remarks

VersionBehavior
Windows 8/Windows 8.1Prompts the user with a dialog box that requests that an app be added to the lock screen. Must be called before registering any background tasks.
Windows Phone 8.1Does not prompt the user, but must be called before registering any background tasks.
Windows 10Does not prompt the user, but must be called before registering any background tasks. You do not need to add the app to the lock screen in order to use background tasks in Windows 10, but you still need to call RequestAccessAsync to request background access.

 

Tip  Starting with Windows 10, it is no longer necessary to call this method from the UI thread.
 

Examples

This example shows this method used to request background access for the app.


var Background = Windows.ApplicationModel.Background;

var promise = Background.BackgroundExecutionManager.requestAccessAsync().then(
    function(result) {
        switch (result) {
            case Background.BackgroundAccessStatus.denied:
                // Windows: Background activity and updates for this app are disabled by the user.
                //
                // Windows Phone: The maximum number of background apps allowed across the system has been reached or
                // background activity and updates for this app are disabled by the user.
                break;
    
            case Background.BackgroundAccessStatus.allowedWithAlwaysOnRealTimeConnectivity:
                // Windows: Added to list of background apps; set up background tasks; 
                // can use the network connectivity broker.
                //
                // Windows Phone: This value is never used on Windows Phone.
                break;
    
            case Background.BackgroundAccessStatus.allowedMayUseActiveRealTimeConnectivity:
                // Windows: Added to list of background apps; set up background tasks;
                // cannot use the network connectivity broker.
                //
                // Windows Phone: This app can register background tasks. Required for all 
                // background tasks on Windows Phone.
                break;
    
            case Background.BackgroundAccessStatus.unspecified:
                // The user didn't explicitly disable or enable access and updates. 
                break;
        }
    });

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

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

BackgroundExecutionManager

 

 

Show: