BackgroundTaskRegistration
BackgroundTaskRegistration
BackgroundTaskRegistration
BackgroundTaskRegistration
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// You can use this class in JavaScript.
- Attributes
| 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 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>// You can use this property in JavaScript.
- Value
- IMapView<PlatForm::String, BackgroundTaskRegistrationGroup> IReadOnlyDictionary<string, BackgroundTaskRegistrationGroup> IReadOnlyDictionary<string, BackgroundTaskRegistrationGroup> IReadOnlyDictionary<string, BackgroundTaskRegistrationGroup>
A dictionary of background task groups.
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
AllTasks 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>// You can use this property in JavaScript.
- Value
- IMapView<PlatForm::Guid, IBackgroundTaskRegistration> IReadOnlyDictionary<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.
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 : PlatForm::String Name { get; }public string Name { get; }Public ReadOnly Property Name As string// You can use this property in JavaScript.
- Value
- PlatForm::String string string string
The description specified with BackgroundTaskBuilder::Name when the task was created.
TaskGroup 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// You can use this property in JavaScript.
- Value
- BackgroundTaskRegistrationGroup BackgroundTaskRegistrationGroup BackgroundTaskRegistrationGroup BackgroundTaskRegistrationGroup
The BackgroundTaskRegistrationGroup that this BackgroundTaskRegistration is a part of.
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
TaskId 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// You can use this property in JavaScript.
- Value
- PlatForm::Guid Guid Guid 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// You can use this property in JavaScript.
This is not intended for use in your code. For all unsupported trigger types, the value returned by this property is null.
Methods
GetTaskGroup(String) 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// You can use this method in JavaScript.
- groupId
- PlatForm::String String String String
The group identifier.
The task group object that is associated with the group identifier.
| 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) 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// You can use this method in JavaScript.
- cancelTask
- bool Boolean 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.
Events
Completed Completed Completed Completed
Attaches a completed event handler to the registered background task.
public : event BackgroundTaskCompletedEventHandler Completedpublic event BackgroundTaskCompletedEventHandler CompletedPublic Event Completed// You can use this event in JavaScript.