Freigeben über


LifetimeContext.GetOrCreate Method

Definition

Retrieves a shared part instance with the specified ID, or if the part instance can not be found, creates and shares a part instance using the specified creator within the specified operation.

public:
 System::Object ^ GetOrCreate(int sharingId, System::Composition::Hosting::Core::CompositionOperation ^ operation, System::Composition::Hosting::Core::CompositeActivator ^ creator);
public object GetOrCreate (int sharingId, System.Composition.Hosting.Core.CompositionOperation operation, System.Composition.Hosting.Core.CompositeActivator creator);
member this.GetOrCreate : int * System.Composition.Hosting.Core.CompositionOperation * System.Composition.Hosting.Core.CompositeActivator -> obj
Public Function GetOrCreate (sharingId As Integer, operation As CompositionOperation, creator As CompositeActivator) As Object

Parameters

sharingId
Int32

The ID of the shared part.

operation
CompositionOperation

An operation in which to create a part, if necessary.

creator
CompositeActivator

An activator that can activate a new part instance, if necessary.

Returns

The new or retrieved part.

Remarks

This method is lock-free if the part instance already exists. If the part instance must be created, a lock will be taken that will serialize other writes that use this method (concurrent reads will continue to be safe and lock-free). It is important that the composition, and thus lock acquisition, is strictly leaf-to-root in the lifetime tree.

Applies to