WebUIBackgroundTaskInstance WebUIBackgroundTaskInstance WebUIBackgroundTaskInstance WebUIBackgroundTaskInstance WebUIBackgroundTaskInstance Class


Represents an instance of a background task that has been triggered to run.

A background task must explicitly call the Web Workers close method to terminate itself after the task has completed.

public : static class WebUIBackgroundTaskInstance
static struct winrt::Windows::UI::WebUI::WebUIBackgroundTaskInstance
public static class WebUIBackgroundTaskInstance
Public Static Class WebUIBackgroundTaskInstance
// This class does not provide a public constructor.
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)



: This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX)



Current Current Current Current Current

Gets the current background task.

public : static IWebUIBackgroundTaskInstance Current { get; }
static IWebUIBackgroundTaskInstance Current();
public static IWebUIBackgroundTaskInstance Current { get; }
Public Static ReadOnly Property Current As IWebUIBackgroundTaskInstance
var iWebUIBackgroundTaskInstance = Windows.UI.WebUI.WebUIBackgroundTaskInstance.current;
IWebUIBackgroundTaskInstance IWebUIBackgroundTaskInstance 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.


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.

See Also