Background​Task​Registration Background​Task​Registration Background​Task​Registration Class

Definition

Represents a background task that has been registered with the system.

public : sealed class BackgroundTaskRegistration : IBackgroundTaskRegistration, IBackgroundTaskRegistration2, IBackgroundTaskRegistration3public sealed class BackgroundTaskRegistration : IBackgroundTaskRegistration, IBackgroundTaskRegistration2, IBackgroundTaskRegistration3Public NotInheritable Class BackgroundTaskRegistration Implements IBackgroundTaskRegistration, IBackgroundTaskRegistration2, IBackgroundTaskRegistration3
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

The system returns an instance of this class when the application calls the BackgroundTaskBuilder.Register method.

Properties

AllTaskGroups AllTaskGroups AllTaskGroups

Gets the background task groups.

public : static IMapView<string, BackgroundTaskRegistrationGroup> AllTaskGroups { get; }public static IReadOnlyDictionary<string, BackgroundTaskRegistrationGroup> AllTaskGroups { get; }Public Static ReadOnly Property AllTaskGroups As IReadOnlyDictionary<string, BackgroundTaskRegistrationGroup>
Value
IMapView<PlatForm::String, BackgroundTaskRegistrationGroup> IReadOnlyDictionary<string, BackgroundTaskRegistrationGroup> IReadOnlyDictionary<string, BackgroundTaskRegistrationGroup>

A dictionary of background task groups.

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

AllTasks AllTasks AllTasks

Enumerates an application's registered background tasks, except for the background tasks registered in a group with Windows.ApplicationModel.Background.BackgroundTaskBuilder.TaskGroup.

public : static IMapView<Guid, IBackgroundTaskRegistration> AllTasks { get; }public static IReadOnlyDictionary<Guid, IBackgroundTaskRegistration> AllTasks { get; }Public Static ReadOnly Property AllTasks As IReadOnlyDictionary<Guid, IBackgroundTaskRegistration>
Value
IMapView<PlatForm::Guid, IBackgroundTaskRegistration> IReadOnlyDictionary<Guid, IBackgroundTaskRegistration> IReadOnlyDictionary<Guid, IBackgroundTaskRegistration>

A view into a map of registered background tasks consisting of the task ID and an IBackgroundTaskRegistration interface.

Attributes

Examples

The following example shows how to use the AllTasks property of the BackgroundTaskRegistration class to retrieve the existing background task registration object for your app's background task (if the task is currently registered).

// The name of the background task for your app.
string name = "ExampleTaskName";


// Get a list of all background tasks. The list is returned as
// a dictionary of IBackgroundTaskRegistration objects.
foreach (var cur in BackgroundTaskRegistration.AllTasks)
{

    if (cur.Value.Name == name)

    {

        // Take some action based on finding the background task.

        //

        // For example, unregister the task: cur.Value.Unregister(true);

        // Or, set a global variable indicating that the task is already registered

    }

}

Name Name Name

Gets the name of a registered background task.

public : PlatForm::String Name { get; }public string Name { get; }Public ReadOnly Property Name As string
Value
PlatForm::String string string

The description specified with BackgroundTaskBuilder::Name when the task was created.

Attributes

TaskGroup TaskGroup TaskGroup

Gets the BackgroundTaskRegistrationGroup that this BackgroundTaskRegistration is a part of.

public : BackgroundTaskRegistrationGroup TaskGroup { get; }public BackgroundTaskRegistrationGroup TaskGroup { get; }Public ReadOnly Property TaskGroup As BackgroundTaskRegistrationGroup
Value
BackgroundTaskRegistrationGroup BackgroundTaskRegistrationGroup BackgroundTaskRegistrationGroup

The BackgroundTaskRegistrationGroup that this BackgroundTaskRegistration is a part of.

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

TaskId TaskId TaskId

Gets the identifier of a registered background task.

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

The unique identifier for the task. This identifier is generated by the system when the task is registered.

Attributes

Trigger Trigger Trigger

This is not intended for use in your code. For all unsupported trigger types, the value returned by this property is null.

public : IBackgroundTrigger Trigger { get; }public IBackgroundTrigger Trigger { get; }Public ReadOnly Property Trigger As IBackgroundTrigger
Value
IBackgroundTrigger IBackgroundTrigger IBackgroundTrigger

This is not intended for use in your code. For all unsupported trigger types, the value returned by this property is null.

Attributes

Methods

GetTaskGroup(String) GetTaskGroup(String) GetTaskGroup(String)

Gets the task group object that is associated with the group identifier.

public : static BackgroundTaskRegistrationGroup GetTaskGroup(PlatForm::String groupId)public static BackgroundTaskRegistrationGroup GetTaskGroup(String groupId)Public Static Function GetTaskGroup(groupId As String) As BackgroundTaskRegistrationGroup
Parameters
groupId
PlatForm::String String String

The group identifier.

Returns

The task group object that is associated with the group identifier.

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Remarks

If no group with the specified ID is found, null is returned.
To get all of the tasks associated with the group, call BackgroundTaskRegistrationGroup.AllTasks()

Unregister(Boolean) Unregister(Boolean) Unregister(Boolean)

Cancels the registration of a registered background task.

public : void Unregister(bool cancelTask)public void Unregister(Boolean cancelTask)Public Function Unregister(cancelTask As Boolean) As void
Parameters
cancelTask
bool Boolean Boolean

True if currently running instances of this background task should be canceled. If this parameter is false, currently running instances are allowed to finish. Canceled instances receive a Canceled event with a cancellation reason of Abort.

Attributes

Events

Completed Completed Completed

Attaches a completed event handler to the registered background task.

public : event BackgroundTaskCompletedEventHandler Completedpublic event BackgroundTaskCompletedEventHandler CompletedPublic Event Completed
Attributes

Progress Progress Progress

Attaches a progress event handler to the registered background task.

public : event BackgroundTaskProgressEventHandler Progresspublic event BackgroundTaskProgressEventHandler ProgressPublic Event Progress
Attributes