WebUIBackgroundTaskInstanceRuntimeClass WebUIBackgroundTaskInstanceRuntimeClass WebUIBackgroundTaskInstanceRuntimeClass WebUIBackgroundTaskInstanceRuntimeClass WebUIBackgroundTaskInstanceRuntimeClass Class


Provides access to an instance of a background task.


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

public : sealed class WebUIBackgroundTaskInstanceRuntimeClass : IBackgroundTaskInstance, IWebUIBackgroundTaskInstance
struct winrt::Windows::UI::WebUI::WebUIBackgroundTaskInstanceRuntimeClass : IBackgroundTaskInstance, IWebUIBackgroundTaskInstance
public sealed class WebUIBackgroundTaskInstanceRuntimeClass : IBackgroundTaskInstance, IWebUIBackgroundTaskInstance
Public NotInheritable Class WebUIBackgroundTaskInstanceRuntimeClass Implements IBackgroundTaskInstance, IWebUIBackgroundTaskInstance
// 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)


To retrieve this object, use the WebUIBackgroundTaskInstance.current property.


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



InstanceId InstanceId InstanceId InstanceId InstanceId

Gets the instance ID of the background task instance.

public : Platform::Guid InstanceId { get; }
Guid InstanceId();
public Guid InstanceId { get; }
Public ReadOnly Property InstanceId As Guid
var guid = webuiBackgroundTaskInstanceRuntimeClass.instanceId;
Guid Guid Guid

A unique identifier for the background task instance. This identifier is generated by the system when the instance is created.

Progress Progress Progress Progress Progress

Gets or sets progress status for a background task instance.

public : unsigned int Progress { get; set; }
uint32_t Progress(); void Progress(uint32_t progress);
public uint Progress { get; set; }
Public ReadWrite Property Progress As uint
var uint = webuiBackgroundTaskInstanceRuntimeClass.progress;
webuiBackgroundTaskInstanceRuntimeClass.progress = uint;
uint uint uint

A value defined by the application to indicate the task's progress.

Succeeded Succeeded Succeeded Succeeded Succeeded

Gets or sets the success value for the background task. The success value is what is returned to the foreground instance of your app in the completed event.

public : Platform::Boolean Succeeded { get; set; }
bool Succeeded(); void Succeeded(bool succeeded);
public bool Succeeded { get; set; }
Public ReadWrite Property Succeeded As bool
var bool = webuiBackgroundTaskInstanceRuntimeClass.succeeded;
webuiBackgroundTaskInstanceRuntimeClass.succeeded = bool;
bool bool bool

An app can set this property to false to indicate that the background task has failed. Otherwise this property is always true.


Once the background task sets this property and has therefore completed its work, the task must explicitly call the Web Workers close method to terminate itself.

SuspendedCount SuspendedCount SuspendedCount SuspendedCount SuspendedCount

Gets the number of times resource management policy caused the background task to be suspended.

public : unsigned int SuspendedCount { get; }
uint32_t SuspendedCount();
public uint SuspendedCount { get; }
Public ReadOnly Property SuspendedCount As uint
var uint = webuiBackgroundTaskInstanceRuntimeClass.suspendedCount;
uint uint uint

The number of times the background task has been suspended.

Task Task Task Task Task

Gets access to the registered background task for this background task instance.

public : BackgroundTaskRegistration Task { get; }
BackgroundTaskRegistration Task();
public BackgroundTaskRegistration Task { get; }
Public ReadOnly Property Task As BackgroundTaskRegistration
var backgroundTaskRegistration = webuiBackgroundTaskInstanceRuntimeClass.task;
BackgroundTaskRegistration BackgroundTaskRegistration BackgroundTaskRegistration

An interface that provides access to the registered background task.

TriggerDetails TriggerDetails TriggerDetails TriggerDetails TriggerDetails

Gets additional information associated with a background task instance.

public : Platform::Object TriggerDetails { get; }
winrt::Windows::Foundation::IInspectable TriggerDetails();
public object TriggerDetails { get; }
Public ReadOnly Property TriggerDetails As object
var object = webuiBackgroundTaskInstanceRuntimeClass.triggerDetails;
object object object

Represents additional information for the background task. If the background task is triggered by a mobile network operator notification, this property is an instance of a NetworkOperatorNotificationEventDetails class. If the background task is triggered by a system event or time event, this property is not used.


GetDeferral() GetDeferral() GetDeferral() GetDeferral() GetDeferral()

Informs the system that the background task might continue to perform work after the IBackgroundTask.Run method returns. This method is not applicable to JavaScript background tasks.

public : BackgroundTaskDeferral GetDeferral()
BackgroundTaskDeferral GetDeferral() const;
public BackgroundTaskDeferral GetDeferral()
Public Function GetDeferral() As BackgroundTaskDeferral
var backgroundTaskDeferral = webuiBackgroundTaskInstanceRuntimeClass.getDeferral();


This method is not applicable for background tasks written in JavaScript. JavaScript background tasks use the Web Workers close method to finish the task after all asynchronous operations have completed.


Canceled Canceled Canceled Canceled Canceled

Attaches a cancellation event handler to the background task instance.

public : event BackgroundTaskCanceledEventHandler Canceled<>
// Register
event_token Canceled(BackgroundTaskCanceledEventHandler<> const& handler) const;

// Revoke with event_token
void Canceled(event_token const& cookie) const;

// Revoke with event_revoker
Canceled_revoker Canceled(auto_revoker_t, BackgroundTaskCanceledEventHandler<> const& handler) const;
public event BackgroundTaskCanceledEventHandler Canceled<>
Public Event BackgroundTaskCanceledEventHandler Canceled( Of )
function onCanceled(eventArgs){/* Your code */}

webuiBackgroundTaskInstanceRuntimeClass.addEventListener("canceled", onCanceled);
webuiBackgroundTaskInstanceRuntimeClass.removeEventListener("canceled", onCanceled);


In most cases, JavaScript background tasks continue to run until the Web Workers close method is called. The system shuts down a background task only when all apps are being closed, for example user log off or system shut down. In that case, Windows fires the canceled event, enabling the background task to complete any final activity before it is closed.