Export (0) Print
Expand All

ContractHandle Class

Provides methods that control the lifetime of an add-in.

System::Object
  System.AddIn.Pipeline::ContractHandle

Namespace:  System.AddIn.Pipeline
Assembly:  System.AddIn (in System.AddIn.dll)

public ref class ContractHandle : IDisposable

The ContractHandle type exposes the following members.

  NameDescription
Public methodContractHandleInitializes a new instance of the ContractHandle class.
Top

  NameDescription
Public propertyContractGets the contract used by a pipeline.
Top

  NameDescription
Public methodStatic memberAppDomainOwnerGets the instance of the add-in-side adapter when the application domain was created.
Public methodStatic memberContractOwnsAppDomainDetermines whether an application domain is owned by the specified contract.
Public methodDispose()Revokes the lifetime token on a contract, regardless of input.
Protected methodDispose(Boolean)Revokes the lifetime token on the contract regardless of input and optionally releases the managed resources.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Overrides Object::Finalize().)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

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.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft