共用方式為


StorageLibraryChangeTrackerOptions 類別

定義

允許來電者在變更追蹤器上呼叫 EnableWithOptions,選擇追蹤所有變更,包括上次變更識別碼,或只追蹤上次變更識別碼。

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

備註

根據預設,在特定文件庫或資料夾上啟用變更追蹤器將會追蹤所有變更詳細資料,以及追蹤上次變更識別碼。藉由將 StorageLibraryChangeTrackerOptions::TrackChangeDetails 設定為 false,並使用類似下列範例的 EnableWithOptions,系統只會追蹤使用較少系統儲存體的最後一個變更識別碼。

如果您的應用程式不需要變更的詳細資料,這是建議的方法。

建構函式

StorageLibraryChangeTrackerOptions()

StorageLibraryChangeTrackerOptions的建構函式,用來設定 StorageFolder 或 StorageLibrary 之變更追蹤器的行為。

屬性

TrackChangeDetails

用來判斷系統是否會追蹤每個個別變更,或只追蹤指定變更追蹤器的最後一個變更識別碼。

適用於

另請參閱