IBackgroundTaskInstance IBackgroundTaskInstance IBackgroundTaskInstance IBackgroundTaskInstance IBackgroundTaskInstance Interface


Provides access to a background task instance.

public : interface IBackgroundTaskInstance
struct winrt::Windows::ApplicationModel::Background::IBackgroundTaskInstance
public interface IBackgroundTaskInstance
Public Interface IBackgroundTaskInstance
// You can't instantiate an interface directly in JavaScript. You can use objects that implement the interface, however.
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)


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 = iBackgroundTaskInstance.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 = iBackgroundTaskInstance.progress;
iBackgroundTaskInstance.progress = uint;
uint uint uint

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

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 = iBackgroundTaskInstance.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 = iBackgroundTaskInstance.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 = iBackgroundTaskInstance.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.

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


If a background task uses an asynchronous operation, it is possible for the Run method to return before the background task has completed its work. As soon as the Run method returns, the system might suspend or terminate the background task host process, which could prevent completion of asynchronous operations started by the background task.

To keep the host process from being suspended or terminated while the background task is running, use the GetDeferral method to get a background task deferral for each asynchronous operation initiated. Then, when the asynchronous operation is finished, call the BackgroundTaskDeferral.Complete method.

Ensure that you complete all background task deferrals. Most background tasks have a timeout after which the app will be suspended or terminated regardless of whether there are any pending deferrals. However, leaving outstanding background task deferrals interferes with the system's ability to manage process lifetimes in a timely way.


Canceled Canceled Canceled Canceled Canceled

Attaches a cancellation event handler to the background task instance.

For Windows Phone 8.x app, if the device becomes low on memory, background tasks may be terminated without any warning and without raising the OnCanceled event. This helps to ensure the user experience of the app in the foreground. Your background task should be designed to handle this scenario.

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 */}

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