共用方式為


StorageLibraryChangeTracker.Enable 方法

定義

多載

Enable()

啟用儲存體程式庫的變更追蹤。

Enable(StorageLibraryChangeTrackerOptions)

根據變更識別碼,針對所有或最新的變更啟用儲存體程式庫的變更追蹤。

Enable()

啟用儲存體程式庫的變更追蹤。

public:
 virtual void Enable() = Enable;
void Enable();
public void Enable();
function enable()
Public Sub Enable ()

適用於

Enable(StorageLibraryChangeTrackerOptions)

根據變更識別碼,針對所有或最新的變更啟用儲存體程式庫的變更追蹤。

public:
 virtual void Enable(StorageLibraryChangeTrackerOptions ^ options) = Enable;
/// [Windows.Foundation.Metadata.Overload("EnableWithOptions")]
void Enable(StorageLibraryChangeTrackerOptions const& options);
[Windows.Foundation.Metadata.Overload("EnableWithOptions")]
public void Enable(StorageLibraryChangeTrackerOptions options);
function enable(options)
Public Sub Enable (options As 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();
    }
}
}

備註

對於只對上次變更識別碼感興趣的應用程式,系統不會將所有變更記錄儲存在裝置上,並將儲存體變大。 在此情況下,ReadBatchAsync 一律會傳回 0 筆記錄。

另請參閱

適用於