StorageLibraryChangeTrackerOptions 类

定义

允许调用方在更改跟踪器上调用 EnableWithOptions,以选择跟踪所有更改,包括上次更改 ID 或仅跟踪上次更改 ID。

public ref class StorageLibraryChangeTrackerOptions sealed
/// [Windows.Foundation.Metadata.Activatable(720896, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 720896)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class StorageLibraryChangeTrackerOptions final
[Windows.Foundation.Metadata.Activatable(720896, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 720896)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class StorageLibraryChangeTrackerOptions
function StorageLibraryChangeTrackerOptions()
Public NotInheritable Class StorageLibraryChangeTrackerOptions
继承
Object Platform::Object IInspectable StorageLibraryChangeTrackerOptions
属性

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

注解

默认情况下,在特定库或文件夹上启用更改跟踪器将跟踪所有更改详细信息,并跟踪上次更改 ID。通过将 StorageLibraryChangeTrackerOptions::TrackChangeDetails 设置为 false 并使用 EnableWithOptions(如以下示例所示),系统将仅跟踪使用较少系统存储的最后一个更改 ID。

如果应用程序不需要有关更改的详细信息,建议使用此方法。

构造函数

StorageLibraryChangeTrackerOptions()

StorageLibraryChangeTrackerOptions 的构造函数,用于为 StorageFolder 或 StorageLibrary 设置更改跟踪器的行为。

属性

TrackChangeDetails

用于确定系统是跟踪每个单独的更改,还是只跟踪给定更改跟踪器的最后一个更改 ID。

适用于

另请参阅