ContextUtil.DeactivateOnReturn Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

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

public static bool DeactivateOnReturn { get; set; }

Property Value

Type: System.Boolean

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

Exception Condition
COMException

There is no COM+ context available.

PlatformNotSupportedException

The platform is not Windows 2000 or later.

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.

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

[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;

    }

}

.NET Framework
Available since 1.1
Return to top
Show: