Udostępnij za pośrednictwem


StorageLibraryChangeTracker.Enable Method

Definition

Overloads

Enable()

Enables change tracking for the storage library.

Enable(StorageLibraryChangeTrackerOptions)

Enables change tracking for the storage library on all or the latest changes based on the change id.

Enable()

Enables change tracking for the storage library.

public:
 virtual void Enable() = Enable;
void Enable();
public void Enable();
function enable()
Public Sub Enable ()

Applies to

Enable(StorageLibraryChangeTrackerOptions)

Enables change tracking for the storage library on all or the latest changes based on the change id.

public:
 virtual void Enable(StorageLibraryChangeTrackerOptions ^ options) = Enable;
/// [Windows.Foundation.Metadata.Overload("EnableWithOptions")]
void Enable(StorageLibraryChangeTrackerOptions const& options);
[Windows.Foundation.Metadata.Overload("EnableWithOptions")]
public void Enable(StorageLibraryChangeTrackerOptions options);
function enable(options)
Public Sub Enable (options As StorageLibraryChangeTrackerOptions)

Parameters

Attributes

Windows requirements

Device family
Windows 10, version 2104 (introduced in 10.0.20348.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v12.0)

Examples

// applications are expected to persist the previous value
UINT64 appsLastPersistedChangeId = StorageLibraryLastChangeId::Unknown();
StorageFolder folder = StorageFolder::GetFolderFromPathAsync(L"my folder path").get();

StorageLibraryChangeTracker tracker = folder.TryGetChangeTracker();
if (tracker != nullptr)
{
StorageLibraryChangeTrackerOptions ops;
ops.TrackChangeDetails(false);
tracker.Enable(ops);

StorageLibraryChangeReader reader = tracker.GetChangeReader();
if (reader != nullptr)
{
    UINT32 changeId = reader.GetLastChangeId();
    if ((changeId == StorageLibraryLastChangeId::Unknown())
    {
        ScanFolderSlow();
    }
    else if (changeId == 0)
    {
        // no changes in the storage folder yet, OR nothing has changed
        ProcessNormalApplicationStartup();
    }
    else if (changeId != appsLastPersistedChangeId)
    {
        // There have been new changes since we’ve last ran, process them
        appsLastPersistedChangeId = changeId;
        ScanFolderForChanges();
    }
    else
    {
        // changeId and our last persisted change id match, also normal application startup
        ProcessNormalApplicationStartup();
    }
}
}

Remarks

For applications only interested in the last change id, the system will not store all change records and bloat the storage on the device. In this case, ReadBatchAsync will always return 0 records.

See also

Applies to