ILinkedUndoContext.BeginTransaction 方法

对设计的一系列更改。如果任何更改失败,则可以停止所有的组中,将该模型保持不变。调用 Commit() 完成事务。如果用户调用中移除,整个组将被回滚。

命名空间:  Microsoft.VisualStudio.Modeling.ExtensionEnablement
程序集:  Microsoft.VisualStudio.Modeling.Sdk.11.0(在 Microsoft.VisualStudio.Modeling.Sdk.11.0.dll 中)

语法

声明
Function BeginTransaction ( _
    description As String _
) As ILinkedUndoTransaction
ILinkedUndoTransaction BeginTransaction(
    string description
)

参数

  • description
    类型:System.String
    标识该事务的任何字符串。

返回值

类型:Microsoft.VisualStudio.Modeling.ExtensionEnablement.ILinkedUndoTransaction
新的事务。在更改完成后,使或中止,并配置此事务。

备注

执行此操作 using 子句的初始值设定项,确保该事务时,在完成更改时发生。

未捕获 using 内的异常块将导致在其中的任何 UML 模型更改回滚。请注意这仅适用于 UML 模型中的更改,而不是对其他变量的更改,外部数据库,文件,依此类推。

事务可以嵌套。

有关更多信息,请参见 如何:使用事务链接模型更新

示例

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 安全性

请参见

参考

ILinkedUndoContext 接口

Microsoft.VisualStudio.Modeling.ExtensionEnablement 命名空间