Search Results for

    Show / Hide Table of Contents

    Class Transaction

    Provides a scope to safely read and write to a Realm. Must use explicitly via BeginWrite().

    Inheritance
    object
    Transaction
    Implements
    IDisposable
    Namespace: Realms
    Assembly: Realm.dll
    Syntax
    public class Transaction : IDisposable
    Remarks

    All access to a Realm occurs within a Transaction. Read transactions are created implicitly.

    Properties

    | Edit this page View Source

    State

    Gets the state of this transaction.

    Declaration
    public TransactionState State { get; }
    Property Value
    Type Description
    TransactionState

    The state of the transaction.

    Methods

    | Edit this page View Source

    Commit()

    Use to save the changes to the realm. If Transaction is declared in a using block, it must be used before the end of that block.

    Declaration
    public void Commit()
    | Edit this page View Source

    CommitAsync(CancellationToken)

    Use to save the changes to the realm. If Transaction is declared in a using block, it must be used before the end of that block. It completes when the changes are effectively written to disk.

    Declaration
    public Task CommitAsync(CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    Optional cancellation token to stop waiting on the returned Task.

    Returns
    Type Description
    Task

    An awaitable Task that completes when the committed changes are effectively written to disk.

    Remarks

    Cancelling the returned Task will not prevent the write to disk but it will immediately resolve the task with a TaskCanceledException. In fact, the commit action can't be stopped and continues running to completion in the background.
    A use case for cancelling this action could be that you want to show users a pop-up indicating that the data is being saved. But, you want to automatically close such pop-up after a certain amount of time. Or, you may want to allow users to manually dismiss that pop-up.

    | Edit this page View Source

    Dispose()

    Will automatically Rollback() the transaction on existing scope, if not explicitly Committed.

    Declaration
    public void Dispose()
    | Edit this page View Source

    Rollback()

    Use explicitly to undo the changes in a Transaction, otherwise it is automatically invoked by exiting the block.

    Declaration
    public void Rollback()

    Implements

    IDisposable
    • Edit this page
    • View Source
    In this article
    Back to top Copyright © 2020-2024 Realm
    Generated by DocFX