Επεξεργασία

Κοινή χρήση μέσω


ContextUtil.DeactivateOnReturn Property

Definition

Gets or sets the done bit in the COM+ context.

public:
 static property bool DeactivateOnReturn { bool get(); void set(bool value); };
public static bool DeactivateOnReturn { get; set; }
static member DeactivateOnReturn : bool with get, set
Public Shared Property DeactivateOnReturn As Boolean

Property Value

true if the object is to be deactivated when the method returns; otherwise, false. The default is false.

Exceptions

There is no COM+ context available.

Examples

The following code example demonstrates the use of the DeactivateOnReturn property to ensure that a ServicedComponent is deactivated after a method call.


[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

Remarks

The COM+ done bit determines how long the object remains active after finishing its work and can affect the duration of a transaction. When a method call returns, COM+ inspects the done bit. If the done bit is true, COM+ deactivates the object. If the done bit is false, the object is not deactivated.

Applies to