BackgroundTaskRegistration.AllTasks 属性

定义

枚举应用程序注册的后台任务,但使用 Windows.ApplicationModel.Background.BackgroundTaskBuilder.TaskGroup 在组中注册的后台任务除外。

public:
 static property IMapView<Platform::Guid, IBackgroundTaskRegistration ^> ^ AllTasks { IMapView<Platform::Guid, IBackgroundTaskRegistration ^> ^ get(); };
static IMapView<winrt::guid, IBackgroundTaskRegistration const&> AllTasks();
public static IReadOnlyDictionary<Guid,IBackgroundTaskRegistration> AllTasks { get; }
var iMapView = BackgroundTaskRegistration.allTasks;
Public Shared ReadOnly Property AllTasks As IReadOnlyDictionary(Of Guid, IBackgroundTaskRegistration)

属性值

由任务 ID 和 IBackgroundTaskRegistration 接口组成的已注册后台任务的映射视图。

示例

以下示例演示如何使用 BackgroundTaskRegistration 类的 AllTasks 属性检索应用后台任务的现有后台任务注册对象, (如果任务当前已注册) 。

// 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
    }
}

适用于

另请参阅