StorageStreamTransaction StorageStreamTransaction StorageStreamTransaction StorageStreamTransaction Class

Definition

Represents a write transaction for a random-access stream.

public : sealed class StorageStreamTransaction : IClosable, IStorageStreamTransaction
public sealed class StorageStreamTransaction : IDisposable, IStorageStreamTransaction
Public NotInheritable Class StorageStreamTransaction Implements IDisposable, IStorageStreamTransaction
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The File Access sample shows you how to use a StorageStreamTransaction object to perform a transacted write operation on a file.


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
}

if ( file !== null) {
    file.openTransactedWriteAsync().then(
        function (transaction) {
            var dataWriter = new Windows.Storage.Streams.DataWriter(transaction.stream);
            dataWriter.writeString("Swift as a shadow");
            dataWriter.storeAsync().then(function (size) {
                transaction.stream.size = size; // reset stream size to override the file
                transaction.commitAsync().done(function () {
                    // Text written to file

                    // Close stream
                    transaction.close();
                });
            });
        },
        // Handle errors with an error function
        function (error) {
            // Proccess errors
        }
    );
}

In the example, file is a local variable that contains a storageFile that represents the file to write.

Properties

Stream Stream Stream Stream

Gets the random-access stream used in the transaction.

public : IRandomAccessStream Stream { get; }
public IRandomAccessStream Stream { get; }
Public ReadOnly Property Stream As IRandomAccessStream
var iRandomAccessStream = storageStreamTransaction.stream;

Methods

Close() Close() Close() Close()

Releases system resources that are exposed by the stream, indicating that the data request is complete.

public : void Close()
This member is not implemented in C#
This member is not implemented in VB.Net
storageStreamTransaction.close();

CommitAsync() CommitAsync() CommitAsync() CommitAsync()

Save the stream to the underlying file.

public : IAsyncAction CommitAsync()
public IAsyncAction CommitAsync()
Public Function CommitAsync() As IAsyncAction
var iAsyncAction = storageStreamTransaction.commitAsync();
Returns

No object or value is returned by this method.

Dispose() Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

This member is not implemented in C++
void Dispose()
Sub Dispose
void Dispose()

See Also