Skip to content

Latest commit

 

History

History
68 lines (55 loc) · 1.98 KB

storagelibrarychangereader_getlastchangeid_1437118371.md

File metadata and controls

68 lines (55 loc) · 1.98 KB
-api-id -api-type
M:Windows.Storage.StorageLibraryChangeReader.GetLastChangeId
winrt method

Windows.Storage.StorageLibraryChangeReader.GetLastChangeId

-description

Gets a unique value representing the last change processed by the indexing service for the given StorageFolder or StorageLibrary.

-returns

A valid change id (> 0) if there have been changes.

Returns 0 if there have been no changes since the last time read or no changes have occurred yet.

Returns StorageLibraryChangeId::Unknown if the change tracker cannot compute the change id, or too many file changes have happened and this value overflows.

-remarks

-see-also

StorageLibraryChangeReader, StorageLibraryLastChangeId

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