StorageLibraryChangeTrackerTrigger StorageLibraryChangeTrackerTrigger StorageLibraryChangeTrackerTrigger StorageLibraryChangeTrackerTrigger StorageLibraryChangeTrackerTrigger Class

Definition

Represents a file change within a StorageFolder that triggers a background task to run.

public : sealed class StorageLibraryChangeTrackerTrigger : IBackgroundTrigger
struct winrt::Windows::ApplicationModel::Background::StorageLibraryChangeTrackerTrigger : IBackgroundTrigger
public sealed class StorageLibraryChangeTrackerTrigger : IBackgroundTrigger
Public NotInheritable Class StorageLibraryChangeTrackerTrigger Implements IBackgroundTrigger
var storageLibraryChangeTrackerTrigger = new storageLibraryChangeTrackerTrigger(tracker);
Attributes

Windows 10 requirements

Device family
Windows 10, version 1803 (introduced v10.0.17134.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v6)

Examples

The following example shows how to create and register a storage library change trigger for the specified folder.

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

Remarks

The background task must be declared in the manifest before the registration can be successful.

Constructors

StorageLibraryChangeTrackerTrigger(StorageLibraryChangeTracker) StorageLibraryChangeTrackerTrigger(StorageLibraryChangeTracker) StorageLibraryChangeTrackerTrigger(StorageLibraryChangeTracker) StorageLibraryChangeTrackerTrigger(StorageLibraryChangeTracker) StorageLibraryChangeTrackerTrigger(StorageLibraryChangeTracker)

Initializes a new StorageLibraryChangeTrackerTrigger instance.

See also