StorageLibraryChangeTrackerTrigger Classe

Definizione

Rappresenta una modifica del file all'interno di un oggetto StorageFolder che attiva l'esecuzione di un'attività in background.

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
Ereditarietà
Object Platform::Object IInspectable StorageLibraryChangeTrackerTrigger
Attributi
Implementazioni

Requisiti Windows

Famiglia di dispositivi
Windows 10, version 1803 (è stato introdotto in 10.0.17134.0)
API contract
Windows.Foundation.UniversalApiContract (è stato introdotto in v6.0)

Esempio

Nell'esempio seguente viene illustrato come creare e registrare un trigger di modifica della libreria di archiviazione per la cartella specificata.

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

Commenti

L'attività in background deve essere dichiarata nel manifesto prima che la registrazione possa essere completata correttamente.

Costruttori

StorageLibraryChangeTrackerTrigger(StorageLibraryChangeTracker)

Inizializza una nuova istanza di StorageLibraryChangeTrackerTrigger .

Si applica a

Vedi anche