Udostępnij przez


StorageLibraryChangeReader.GetLastChangeId Method

Definition

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

public:
 virtual unsigned long long GetLastChangeId() = GetLastChangeId;
uint64_t GetLastChangeId();
public ulong GetLastChangeId();
function getLastChangeId()
Public Function GetLastChangeId () As ULong

Returns

UInt64

unsigned long long

uint64_t

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.

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

Applies to

See also