StorageLibraryChangeTrackerTrigger Classe

Definição

Representa uma alteração de arquivo em uma StorageFolder que dispara uma tarefa em segundo plano a ser executada.

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
Herança
Object Platform::Object IInspectable StorageLibraryChangeTrackerTrigger
Atributos
Implementações

Requisitos do Windows

Família de dispositivos
Windows 10, version 1803 (introduzida na 10.0.17134.0)
API contract
Windows.Foundation.UniversalApiContract (introduzida na v6.0)

Exemplos

O exemplo a seguir mostra como criar e registrar um gatilho de alteração de biblioteca de armazenamento para a pasta especificada.

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

Comentários

A tarefa em segundo plano deve ser declarada no manifesto antes que o registro possa ser bem-sucedido.

Construtores

StorageLibraryChangeTrackerTrigger(StorageLibraryChangeTracker)

Inicializa uma nova instância de StorageLibraryChangeTrackerTrigger .

Aplica-se a

Confira também