Class Transaction
Provides a scope to safely read and write to a Realm. Must use explicitly via BeginWrite().
Implements
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 SourceState
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 SourceCommit()
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()
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.
Dispose()
Will automatically Rollback() the transaction on existing scope, if not explicitly Committed.
Declaration
public void Dispose()
Rollback()
Use explicitly to undo the changes in a Transaction, otherwise it is automatically invoked by exiting the block.
Declaration
public void Rollback()