StorageLibraryChangeReader.GetLastChangeId 方法

定义

获取一个唯一值,该值表示索引服务为给定 StorageFolder 或 StorageLibrary 处理的最后一次更改。

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

返回

UInt64

unsigned long long

uint64_t

如果发生更改,则有效的更改 ID (> 0) 。

如果自上次读取以来没有更改或尚未发生任何更改,则返回 0。

如果更改跟踪器无法计算更改 ID,或者发生了太多文件更改且此值溢出,则返回 StorageLibraryChangeId::Unknown。

Windows 要求

设备系列
Windows 10, version 2104 (在 10.0.20348.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v12.0 中引入)

示例

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

适用于

另请参阅