CachedFileManager 類別

定義

可讓應用程式管理檔案的即時更新。

public ref class CachedFileManager abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CachedFileManager final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public static class CachedFileManager
Public Class CachedFileManager
繼承
Object Platform::Object IInspectable CachedFileManager
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

[檔案選擇器] 範例示範如何使用 CachedFileManager 延遲檔案的更新,直到應用程式完成修改檔案為止。

if (file != null)
{
    // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
    CachedFileManager.DeferUpdates(file);

    // Write to file
    await FileIO.AppendTextAsync(file, "Swift as a shadow");
    // Let Windows know that we're finished changing the file so the server app can update the remote version of the file.

    // Complete updates. (May require Windows to ask for user input.)
    FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
    switch (status)
    {
        case FileUpdateStatus.Complete:
            // Perform additional tasks like notifying user of status
            break;

        case FileUpdateStatus.CompleteAndRenamed:
            // Perform additional tasks like notifying user of status, or storing the renamed file for future use
            break;

        default:
            // Perform additional tasks like notifying user of status
            break;
    }
}

在此範例中, file 是一個區域變數,其中包含代表延遲更新之檔案的 StorageFile

備註

這個類別是靜態的,無法具現化。 請改為直接呼叫 方法。

一般而言,當這些檔案變更時,Windows 會隱含起始其他應用程式所提供的檔案更新。  不過,您可以呼叫 DeferUpdates來控制何時起始更新。 如果您使用此方法會延後,直到您呼叫 CompleteUpdatesAsync 來起始它們為止。

方法

CompleteUpdatesAsync(IStorageFile)

起始指定檔案的更新。 此方法會連絡提供檔案以執行更新的應用程式。

DeferUpdates(IStorageFile)

讓應用程式延遲指定檔案的即時更新。

適用於

另請參閱