Megosztás a következőn keresztül:


StorageLibraryChangeTrackerTrigger Class

Definition

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

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
Inheritance
Object Platform::Object IInspectable StorageLibraryChangeTrackerTrigger
Attributes
Implements

Windows requirements

Device family
Windows 10, version 1803 (introduced in 10.0.17134.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v6.0)

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)

Initializes a new StorageLibraryChangeTrackerTrigger instance.

Applies to

See also