WebUIBackgroundTaskInstance.current property

Gets the current background task.


var current = Windows.UI.WebUI.WebUIBackgroundTaskInstance.current;

Property value

Type: IWebUIBackgroundTaskInstance

The current background task. This property can only be accessed in the context of a background task. This property is null in a foreground app.


An app creates a background task by using the BackgroundTaskBuilder class. The SetTrigger method must be set to the event trigger for the task. The TaskEntryPoint must specify a JavaScript file containing the code to run. The app then registers the background task by calling the Register method. When the trigger fires, the system executes the code in the JavaScript file.

The app must also specify the JavaScript file in the <Extensions> section of the app manifest. For example: <Extension Category="windows.backgroundTasks" StartPage = "js\backgroundtask.js">..

When a background task is run, it can use the object returned from the Current property to set the success or failure of the background task and to access properties of the task.

After the background task finishes its work, the task must call the Web Workers close method to terminate itself. This way it doesn't continue to consume the user's memory and battery. Additionally only one background task for the same trigger can run at a time so the previous task must be closed before a new one can be triggered.

Note   Background tasks are meant to be short lived tasks. In general you should not register for event callbacks in a background task. In the case that you do register for a Windows Runtime event and the foreground instance of your app also registers for that event, the callback in your background task may be unreliable.

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0





Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]





See also




© 2015 Microsoft