I​Background​Task​Instance I​Background​Task​Instance I​Background​Task​Instance Interface

Definition

Provides access to a background task instance.

public : interface IBackgroundTaskInstancepublic interface IBackgroundTaskInstancePublic Interface IBackgroundTaskInstance
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Properties

InstanceId InstanceId InstanceId

Gets the instance ID of the background task instance.

public : PlatForm::Guid InstanceId { get; }public Guid InstanceId { get; }Public ReadOnly Property InstanceId As Guid
Value
PlatForm::Guid Guid Guid

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

Attributes

Progress Progress Progress

Gets or sets progress status for a background task instance.

public : unsigned short Progress { get; set; }public uint Progress { get; set; }Public ReadWrite Property Progress As uint
Value
unsigned short uint uint

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

Attributes

SuspendedCount SuspendedCount SuspendedCount

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

public : unsigned short SuspendedCount { get; }public uint SuspendedCount { get; }Public ReadOnly Property SuspendedCount As uint
Value
unsigned short uint uint

The number of times the background task has been suspended.

Attributes

Task Task Task

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

public : BackgroundTaskRegistration Task { get; }public BackgroundTaskRegistration Task { get; }Public ReadOnly Property Task As BackgroundTaskRegistration
Value
BackgroundTaskRegistration BackgroundTaskRegistration BackgroundTaskRegistration

An interface that provides access to the registered background task.

Attributes

TriggerDetails TriggerDetails TriggerDetails

Gets additional information associated with a background task instance.

public : PlatForm::Object TriggerDetails { get; }public object TriggerDetails { get; }Public ReadOnly Property TriggerDetails As object
Value
PlatForm::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.

Attributes

Methods

GetDeferral() GetDeferral() GetDeferral()

Informs the system that the background task might continue to perform work after the IBackgroundTask.Run method returns.

public : BackgroundTaskDeferral GetDeferral()public BackgroundTaskDeferral GetDeferral()Public Function GetDeferral() As BackgroundTaskDeferral
Returns
Attributes

Remarks

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.

Events

Canceled Canceled Canceled

Attaches a cancellation event handler to the background task instance.

For Windows Phone Store 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 : abstract event BackgroundTaskCanceledEventHandler Canceledpublic abstract event BackgroundTaskCanceledEventHandler CanceledPublic MustInherit Event Canceled
Attributes