TransactionScope.Complete Method ()


Indicates that all operations within the scope are completed successfully.

Namespace:   System.Transactions
Assembly:  System.Transactions (in System.Transactions.dll)

member Complete : unit -> unit

Exception Condition

This method has already been called once.

When you are satisfied that all operations within the scope are completed successfully, you should call this method only once to inform that transaction manager that the state across all resources is consistent, and the transaction can be committed. It is very good practice to put the call as the last statement in the using block.

For more information on how this method is used, see the Implementing An Implicit Transaction Using Transaction Scope topic.

Failing to call this method aborts the transaction, because the transaction manager interprets this as a system failure, or exceptions thrown within the scope of transaction. However, you should also note that calling this method does not guarantee a commit of the transaction. It is merely a way of informing the transaction manager of your status. After calling this method, you can no longer access the ambient transaction via the Current property, and trying to do so results in an exception being thrown.

The actual work of commit between the resources manager happens at the End Using statement if the TransactionScope object created the transaction. If it did not create the transaction, the commit occurs whenever Commit is called by the owner of the CommittableTransaction object. At that point the Transaction Manager calls the resource managers and informs them to either commit or rollback, based on whether this method was called on the TransactionScope object.

The following example demonstrates how to use the TransactionScope class to define a block of code to participate in a transaction.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0

TransactionScope Class
System.Transactions Namespace
Implementing An Implicit Transaction Using Transaction Scope

Return to top