ContractHandle Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides methods that control the lifetime of an add-in.
public ref class ContractHandle : IDisposable
public class ContractHandle : IDisposable
type ContractHandle = class
interface IDisposable
Public Class ContractHandle
Implements IDisposable
- Inheritance
-
ContractHandle
- Implements
Examples
The following example shows how to set the lifetime token handle in a contract-to-view adapter on the add-in side of a pipeline.
private CalculatorContracts.ICalc2Contract _contract;
private System.AddIn.Pipeline.ContractHandle _handle;
public CalculatorContractToViewHostAdapter(ICalc2Contract contract) {
_contract = contract;
_handle = new System.AddIn.Pipeline.ContractHandle(contract);
}
Private _contract As ICalc2Contract
Private _handle As ContractHandle
Public Sub New(ByVal contract As ICalc2Contract)
_contract = contract
_handle = New ContractHandle(contract)
End Sub
Remarks
Because the add-in model provides the ability for add-ins to communicate between application domains and between processes, it cannot rely on the garbage collector to reclaim them. This class provides a reference counting mechanism for the add-in by obtaining a lifetime token to its contract.
When a ContractHandle object is constructed, it calls the AcquireLifetimeToken method on the contract that is passed to the constructor. When the ContractHandle object is disposed or finalized, it calls the RevokeLifetimeToken method on the contract, which removes its hold on the contract.
Adapters implement the contract. The ContractHandle class is designed to be used in a contract-to-view adapter to help pipeline developers manage the lifetime of the contract that is being adapted. Typically, an instance of this class is instantiated during the construction of the adapter class and is stored in an instance field of the adapter. When the adapter class is garbage-collected, the ContractHandle object will also be collected and the ContractHandle object will revoke the lifetime token on the contract.
It is recommended that your view-to-contract adapters inherit from the ContractBase class. You can then use a default implementation for the members of IContract, which means you need to implement only the members of your specific contract.
Constructors
ContractHandle(IContract) |
Initializes a new instance of the ContractHandle class. |
Properties
Contract |
Gets the contract used by a pipeline. |
Methods
AppDomainOwner(AppDomain) |
Gets the instance of the add-in-side adapter when the application domain was created. |
ContractOwnsAppDomain(IContract, AppDomain) |
Determines whether an application domain is owned by the specified contract. |
Dispose() |
Revokes the lifetime token on a contract, regardless of input. |
Dispose(Boolean) |
Revokes the lifetime token on the contract regardless of input and optionally releases the managed resources. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Finalize() |
Releases the resources associated with the ContractHandle instance. |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |