StorageStreamTransaction 類別

定義

表示隨機存取資料流程的寫入交易。

public ref class StorageStreamTransaction sealed : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class StorageStreamTransaction final : IClosable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class StorageStreamTransaction : System.IDisposable
Public NotInheritable Class StorageStreamTransaction
Implements IDisposable
繼承
Object Platform::Object IInspectable StorageStreamTransaction
屬性
實作

Windows 需求

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

範例

檔案 存取範例 示範如何使用 StorageStreamTransaction 物件對檔案執行交易寫入作業。

try
{
    if (file != null)
    {
        using (StorageStreamTransaction transaction = await file.OpenTransactedWriteAsync())
        {
            using (DataWriter dataWriter = new DataWriter(transaction.Stream))
            {
                dataWriter.WriteString("Swift as a shadow");
                transaction.Stream.Size = await dataWriter.StoreAsync(); // reset stream size to override the file
                await transaction.CommitAsync();
            }
        }
    }
}
// Use catch blocks to handle errors
catch (FileNotFoundException)
{
    // For example, handle a file not found error
}

在此範例中, file 是一個區域變數,其中包含代表要寫入之檔案的 StorageFile

屬性

Stream

取得交易中使用的隨機存取資料流程。

方法

Close()

釋放資料流程所公開的系統資源,指出資料要求已完成。

CommitAsync()

將資料流程儲存至基礎檔案。

Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

適用於

另請參閱