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 WebUIBackgroundTaskInstancepublic static class WebUIBackgroundTaskInstancePublic Static Class WebUIBackgroundTaskInstancepublic static class WebUIBackgroundTaskInstance



: 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)


Properties summary

Gets the current background task.


  • Current

    Gets the current background task.

    public static IWebUIBackgroundTaskInstance Current { get; }public static IWebUIBackgroundTaskInstance Current { get; }Public Static ReadOnly Property Current As IWebUIBackgroundTaskInstancepublic static IWebUIBackgroundTaskInstance Current { get; }

    Property Value


    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.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)