BackgroundTaskRegistration class

Applies to Windows and Windows Phone

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

Syntax


var backgroundTaskRegistration = Windows.ApplicationModel.Background.BackgroundTaskRegistration;

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

Members

The BackgroundTaskRegistration class has these types of members:

Events

The BackgroundTaskRegistration class has these events.

EventDescription
Completed Attaches a completed event handler to the registered background task.
Progress Attaches a progress event handler to the registered background task.

 

Methods

The BackgroundTaskRegistration class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
Unregister Cancels the registration of a registered background task.

 

Properties

The BackgroundTaskRegistration class has these properties.

PropertyAccess typeDescription

AllTasks

Read-onlyEnumerates an application's registered background tasks.

Name

Read-onlyGets the name of a registered background task.

TaskId

Read-onlyGets the identifier of a registered background task.

Trigger

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

 

Remarks

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

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:
        //
        // TaskAlreadyRegistered = true;
    }
}

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.ApplicationModel.Background
Windows::ApplicationModel::Background [C++]

Metadata

Windows.winmd

 

 

Show:
© 2014 Microsoft