ContextUtil.MyTransactionVote 属性

定义

获取或设置 COM+ 上下文中的 consistent 位。

public:
 static property System::EnterpriseServices::TransactionVote MyTransactionVote { System::EnterpriseServices::TransactionVote get(); void set(System::EnterpriseServices::TransactionVote value); };
public static System.EnterpriseServices.TransactionVote MyTransactionVote { get; set; }
static member MyTransactionVote : System.EnterpriseServices.TransactionVote with get, set
Public Shared Property MyTransactionVote As TransactionVote

属性值

TransactionVote 值之一,可以是 CommitAbort

例外

没有可用的 COM+ 上下文。

示例

下面的代码示例演示如何使用 MyTransactionVote 属性创建事务性 ServicedComponent


[assembly:System::Reflection::AssemblyKeyFile("Transaction.snk")];
[Transaction]
public ref class TransactionalComponent: public ServicedComponent
{
public:
   void TransactionalMethod( String^ data )
   {
      ContextUtil::DeactivateOnReturn = true;
      ContextUtil::MyTransactionVote = TransactionVote::Abort;
      
      // do work with data
      ContextUtil::MyTransactionVote = TransactionVote::Commit;
   }

};
[Transaction]
public class TransactionalComponent : ServicedComponent
{

    public void TransactionalMethod (string data)
    {

      ContextUtil.DeactivateOnReturn = true;
      ContextUtil.MyTransactionVote = TransactionVote.Abort;

      // Do work with data. Return if any errors occur.

      // Vote to commit. If any errors occur, this code will not execute.
      ContextUtil.MyTransactionVote = TransactionVote.Commit;
    }
}
<Transaction()>  _
Public Class TransactionalComponent
    Inherits ServicedComponent
    
    
    Public Sub TransactionalMethod(ByVal data As String) 
        
        ContextUtil.DeactivateOnReturn = True
        ContextUtil.MyTransactionVote = TransactionVote.Abort
        
        ' Do work with data. Return if any errors occur.
        ' Vote to commit. If any errors occur, this code will not execute.
        ContextUtil.MyTransactionVote = TransactionVote.Commit
    
    End Sub
End Class

注解

当 设置为 CommitMyTransactionVote,COM+ consistent 位设置为 true ,COM+ 上下文投票以提交事务。 如果 MyTransactionVote 设置为 Abort,则 consistent 位设置为 false ,COM+ 上下文将投票中止事务。 位的 consistent 默认值为 true

consistent 将投票转换为提交或中止其执行事务,位 done 将最终完成投票。 当方法调用返回时或对象停用时,done当位设置为 true 时,COM+ 将检查consistent位。 尽管对象的 consistent 位可以在每个方法调用中重复更改,但只有最后一次更改计数。

适用于