Method CommitAsync
CommitAsync(CancellationToken)
Commits the transaction, making the files it added and deleted permanent in the repository.
Declaration
Task CommitAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A cancellation token that cancels the call before the commit has started. A commit that has started is not interrupted. |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
A failure to commit an individual file is not thrown: the file stays accessible in an indeterminate state for the next cleanup pass to resolve, and the failure is reported through TransactionCompletionFailed. Once this method has returned, every file of the transaction is therefore committed or indeterminate, and none has been rolled back.
What has happened when this method throws depends on the exception. An OperationCanceledException means that nothing has been committed: the transaction is still open, and disposing it rolls it back. So once the application's database has committed, pass None, or a cancellation could discard files that the database references. Any other exception comes from a TransactionCompletionFailed handler that threw, once every file had been attempted, or from the repository having been disposed. Neither means that the transaction was rolled back: every file is committed or left indeterminate as above, and disposing the transaction rolls nothing back.
Committing a transaction that has itself been disposed is an error of the caller and throws an ObjectDisposedException as well: the call commits nothing, and a transaction that was disposed without having been committed was rolled back by its disposal.
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | The token was cancelled before the commit had started. Nothing has been committed. |
| ObjectDisposedException | The transaction has been disposed: nothing is committed. Or the repository has been disposed: the files that had not been committed yet are left indeterminate. |