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)

屬性值

包含工作識別碼和 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
    }
}

適用於

另請參閱