BackgroundTaskRegistration BackgroundTaskRegistration BackgroundTaskRegistration BackgroundTaskRegistration Class

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

Syntax

Declaration

public sealed class BackgroundTaskRegistrationpublic sealed class BackgroundTaskRegistrationPublic NotInheritable Class BackgroundTaskRegistration

Remarks

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

Properties summary

Enumerates an application's registered background tasks.

Gets the name of a registered background task.

Gets the identifier of a registered background task.

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

Prerelease. Gets the background task groups.

Prerelease. Gets the BackgroundTaskRegistrationGroup that this BackgroundTaskRegistration is a part of.

Methods summary

Cancels the registration of a registered background task.

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

Events summary

Attaches a completed event handler to the registered background task.

Attaches a progress event handler to the registered background task.

Properties

  • AllTasks
    AllTasks
    AllTasks
    AllTasks

    Enumerates an application's registered background tasks.

    public static IMapView<IBackgroundTaskRegistration> AllTasks { get; }public static IMapView<IBackgroundTaskRegistration> AllTasks { get; }Public Static ReadOnly Property AllTasks As IMapView<IBackgroundTaskRegistration>

    Property Value

    Remarks

    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
    Name

    Gets the name of a registered background task.

    public string Name { get; }public string Name { get; }Public ReadOnly Property Name As string

    Property Value

    • string
      string
      string
      string

      The description specified with Name when the task was created.

  • TaskId
    TaskId
    TaskId
    TaskId

    Gets the identifier of a registered background task.

    public Guid TaskId { get; }public Guid TaskId { get; }Public ReadOnly Property TaskId As Guid

    Property Value

    • System.Guid
      System.Guid
      System.Guid
      System.Guid

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

  • Trigger
    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

    Property Value

  • AllTaskGroups
    AllTaskGroups
    AllTaskGroups
    AllTaskGroups

    Prerelease. Gets the background task groups.

    public static IMapView<BackgroundTaskRegistrationGroup> AllTaskGroups { get; }public static IMapView<BackgroundTaskRegistrationGroup> AllTaskGroups { get; }Public Static ReadOnly Property AllTaskGroups As IMapView<BackgroundTaskRegistrationGroup>

    Property Value

    • A dictionary of background task groups.

  • TaskGroup
    TaskGroup
    TaskGroup
    TaskGroup

    Prerelease. Gets the BackgroundTaskRegistrationGroup that this BackgroundTaskRegistration is a part of.

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

    Property Value

Methods

  • Unregister(System.Boolean)
    Unregister(System.Boolean)
    Unregister(System.Boolean)
    Unregister(System.Boolean)

    Cancels the registration of a registered background task.

    public void Unregister(System.Boolean cancelTask)public void Unregister(System.Boolean cancelTask)Public Function Unregister(cancelTask As System.Boolean) As void

    Parameters

    • cancelTask
      System.Boolean
      System.Boolean
      System.Boolean
      System.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.

  • GetTaskGroup(System.String)
    GetTaskGroup(System.String)
    GetTaskGroup(System.String)
    GetTaskGroup(System.String)

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

    public static BackgroundTaskRegistrationGroup GetTaskGroup(System.String groupId)public static BackgroundTaskRegistrationGroup GetTaskGroup(System.String groupId)Public Static Function GetTaskGroup(groupId As System.String) As BackgroundTaskRegistrationGroup

    Parameters

    • groupId
      System.String
      System.String
      System.String
      System.String

      The group identifier.

    Returns

    Remarks

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

Events

  • Completed
    Completed
    Completed
    Completed

    Attaches a completed event handler to the registered background task.

    public event BackgroundTaskCompletedEventHandler Completedpublic event BackgroundTaskCompletedEventHandler CompletedPublic Event Completed
  • Progress
    Progress
    Progress
    Progress

    Attaches a progress event handler to the registered background task.

    public event BackgroundTaskProgressEventHandler Progresspublic event BackgroundTaskProgressEventHandler ProgressPublic Event Progress

Attributes

Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ContractVersionAttribute

Details

Assembly

Windows.ApplicationModel.Background.dll