StorageLibraryChangeTrackerTrigger Classe

Définition

Représente une modification de fichier dans un StorageFolder qui déclenche l’exécution d’une tâche en arrière-plan.

public ref class StorageLibraryChangeTrackerTrigger sealed : IBackgroundTrigger
/// [Windows.Foundation.Metadata.Activatable(Windows.ApplicationModel.Background.IStorageLibraryChangeTrackerTriggerFactory, 393216, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 393216)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class StorageLibraryChangeTrackerTrigger final : IBackgroundTrigger
[Windows.Foundation.Metadata.Activatable(typeof(Windows.ApplicationModel.Background.IStorageLibraryChangeTrackerTriggerFactory), 393216, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 393216)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class StorageLibraryChangeTrackerTrigger : IBackgroundTrigger
function StorageLibraryChangeTrackerTrigger(tracker)
Public NotInheritable Class StorageLibraryChangeTrackerTrigger
Implements IBackgroundTrigger
Héritage
Object Platform::Object IInspectable StorageLibraryChangeTrackerTrigger
Attributs
Implémente

Configuration requise pour Windows

Famille d’appareils
Windows 10, version 1803 (introduit dans 10.0.17134.0)
API contract
Windows.Foundation.UniversalApiContract (introduit dans v6.0)

Exemples

L’exemple suivant montre comment créer et inscrire un déclencheur de modification de bibliothèque de stockage pour le dossier spécifié.

private async Task<bool> RegisterBackgroundTask(StorageFolder folder)
{
    StorageLibraryChangeTracker tracker = folder.TryGetChangeTracker();
    if (tracker != null)
    {
        tracker.Enable();

        StorageLibraryChangeTrackerTrigger trigger = new StorageLibraryChangeTrackerTrigger(tracker);

        string name = "StorageLibraryChangeTrackerTask"; // a friendly task name
        string taskEntryPoint = "Tasks.StorageLibraryChangeTrackerTask";

        var access = await BackgroundExecutionManager.RequestAccessAsync(); // to register background tasks, you must first call RequestAccessAsync()

        BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
        builder.Name = name;
        builder.TaskEntryPoint = taskEntryPoint;
        builder.SetTrigger(trigger);
        BackgroundTaskRegistration task = builder.Register();

        return true;
    }

    // Not getting a tracker means we don't have access to the folder or it’s not a physical folder
    return false;
}

Remarques

La tâche en arrière-plan doit être déclarée dans le manifeste pour que l’inscription puisse réussir.

Constructeurs

StorageLibraryChangeTrackerTrigger(StorageLibraryChangeTracker)

Initialise une nouvelle instance StorageLibraryChangeTrackerTrigger.

S’applique à

Voir aussi