Interface IObjectPool<T>
- Namespace
- CodeProject.ObjectPool
- Assembly
- CodeProject.ObjectPool.dll
Describes all methods available on Object Pools.
public interface IObjectPool<T> where T : PooledObject
Type Parameters
T
The type of the objects stored in the pool.
Properties
AsyncFactoryMethod
Func<CancellationToken, Task<T>> AsyncFactoryMethod { get; }
Property Value
- Func<CancellationToken, Task<T>>
Diagnostics
Gets or sets the Diagnostics class for the current Object Pool, whose goal is to record data about how the pool operates. By default, however, an object pool records anything, in order to be most efficient; in any case, you can enable it through the Enabled property.
ObjectPoolDiagnostics Diagnostics { get; set; }
Property Value
FactoryMethod
Gets the Factory method that will be used for creating new objects.
Func<T>? FactoryMethod { get; }
Property Value
- Func<T>
MaximumPoolSize
Gets or sets the maximum number of objects that could be available at the same time in the pool.
int MaximumPoolSize { get; set; }
Property Value
ObjectsInPoolCount
Gets the count of the objects currently in the pool.
int ObjectsInPoolCount { get; }
Property Value
Methods
Clear()
Clears the pool and destroys each object stored inside it.
void Clear()
GetObject()
Gets a monitored object from the pool.
T GetObject()
Returns
- T
A monitored object from the pool.
Exceptions
- InvalidOperationException
If a custom async factory method has been specified, this exception is thrown in order not to perform a sync-over- async operation, which might lead to deadlocks.
GetObjectAsync(CancellationToken)
Gets a monitored object from the pool.
Task<T> GetObjectAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenCancellation token
Returns
- Task<T>
A monitored object from the pool.