Freigeben über


ILinkedUndoContext.BeginTransaction Method

Group a series of changes to the model. If any change fails, you can abort the whole group, leaving the model unchanged. Call Commit() to complete the transaction. If the user calls undo, the whole group will be rolled back.

Namespace:  Microsoft.VisualStudio.Modeling.ExtensionEnablement
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.12.0 (in Microsoft.VisualStudio.Modeling.Sdk.12.0.dll)

Syntax

'Declaration
Function BeginTransaction ( _
    description As String _
) As ILinkedUndoTransaction
ILinkedUndoTransaction BeginTransaction(
    string description
)
ILinkedUndoTransaction^ BeginTransaction(
    String^ description
)
abstract BeginTransaction : 
        description:string -> ILinkedUndoTransaction
function BeginTransaction(
    description : String
) : ILinkedUndoTransaction

Parameters

  • description
    Type: System.String

    Any string that identifies the transaction.

Return Value

Type: Microsoft.VisualStudio.Modeling.ExtensionEnablement.ILinkedUndoTransaction
The new transaction. When your changes are complete, Commit or Abort, and dispose this transaction.

Remarks

Perform this operation in the initializer of a using clause, to ensure that the transaction is disposed when you have finished your changes.

An exception that is not caught inside the using block will cause all the UML model changes inside it to be rolled back. Note that this applies only to changes on the UML model, and not to changes that have been made to other variables, external databases, files, and so on.

Transactions can be nested.

For more information, see How to: Link Model Updates using Transactions.

Examples

try
{
  using (ILinkedUndoTransaction transaction =
              LinkedUndoContext.BeginTransaction("Swap names"))
  { 
    Operation1(); 
    Operation2();
    // Any exception in the preceding statements
    // will undo all of the changes in the model.
    transaction.Commit(); // Always remember Commit()!
  }
}
catch ()
{
    // If control reaches here,
    // Operation1 and Operation2 have
    // made no change to the model.
}

.NET Framework Security

See Also

Reference

ILinkedUndoContext Interface

Microsoft.VisualStudio.Modeling.ExtensionEnablement Namespace