WithConcurrencyController(IConcurrencyController)
Sets the ambient concurrency controller for the current thread. Until the returned AmbientConcurrencyControllerContext value is disposed, thread-aware objects created in the current thread will be assigned to the given concurrency controller.
Declaration
public static AmbientConcurrencyControllerContext WithConcurrencyController(IConcurrencyController concurrencyController)Parameters
| Type | Name | Description |
|---|---|---|
| IConcurrencyController | concurrencyController | The ambient concurrency controller. Use the ConcurrencyControllerFactory class to create new concurrency controllers. |
Returns
| Type | Description |
|---|---|
| AmbientConcurrencyControllerContext | An IDisposable value representing the ambient concurrency controller context. |
Remarks
This method can be used to optimize performance when creating a large tree of thread-aware objects that need to share the same concurrency controller. When a tree is built from the leaves to the root without this method, a concurrency controller is created for each sub-tree root, and the controllers of a whole sub-tree are replaced each time the sub-tree is assigned to a parent, which can make the instantiation cost quadratic.