Table of Contents

Class TimedObjectPool<T>

Namespace
CodeProject.ObjectPool
Assembly
CodeProject.ObjectPool.dll

A pool where objects are automatically removed after a period of inactivity.

public class TimedObjectPool<T> : ObjectPool<T>, ITimedObjectPool<T>, IObjectPool<T> where T : PooledObject

Type Parameters

T

The type of the object that which will be managed by the pool. The pooled object have to be a sub-class of PooledObject.

Inheritance
TimedObjectPool<T>
Implements
Inherited Members

Constructors

TimedObjectPool(Func<CancellationToken, Task<T>>, TimeSpan)

Initializes a new timed pool with specified factory method and timeout.

public TimedObjectPool(Func<CancellationToken, Task<T>> asyncFactoryMethod, TimeSpan timeout)

Parameters

asyncFactoryMethod Func<CancellationToken, Task<T>>

The async factory method that will be used to create new objects.

timeout TimeSpan

The timeout of each pooled object.

Exceptions

ArgumentOutOfRangeException

timeout is less than or equal to Zero.

TimedObjectPool(Func<T>, TimeSpan)

Initializes a new timed pool with specified factory method and timeout.

public TimedObjectPool(Func<T> factoryMethod, TimeSpan timeout)

Parameters

factoryMethod Func<T>

The factory method that will be used to create new objects.

timeout TimeSpan

The timeout of each pooled object.

Exceptions

ArgumentOutOfRangeException

timeout is less than or equal to Zero.

TimedObjectPool(int, Func<CancellationToken, Task<T>>?, TimeSpan)

Initializes a new timed pool with specified factory method, maximum size and timeout.

public TimedObjectPool(int maximumPoolSize, Func<CancellationToken, Task<T>>? asyncFactoryMethod, TimeSpan timeout)

Parameters

maximumPoolSize int

The maximum pool size limit.

asyncFactoryMethod Func<CancellationToken, Task<T>>

The async factory method that will be used to create new objects.

timeout TimeSpan

The timeout of each pooled object.

Exceptions

ArgumentOutOfRangeException

maximumPoolSize is less than or equal to zero. timeout is less than or equal to Zero.

TimedObjectPool(int, Func<T>?, TimeSpan)

Initializes a new timed pool with specified factory method, maximum size and timeout.

public TimedObjectPool(int maximumPoolSize, Func<T>? factoryMethod, TimeSpan timeout)

Parameters

maximumPoolSize int

The maximum pool size limit.

factoryMethod Func<T>

The factory method that will be used to create new objects.

timeout TimeSpan

The timeout of each pooled object.

Exceptions

ArgumentOutOfRangeException

maximumPoolSize is less than or equal to zero. timeout is less than or equal to Zero.

TimedObjectPool(int, TimeSpan)

Initializes a new timed pool with specified maximum pool size and timeout.

public TimedObjectPool(int maximumPoolSize, TimeSpan timeout)

Parameters

maximumPoolSize int

The maximum pool size limit.

timeout TimeSpan

The timeout of each pooled object.

Exceptions

ArgumentOutOfRangeException

maximumPoolSize is less than or equal to zero. timeout is less than or equal to Zero.

TimedObjectPool(TimeSpan)

Initializes a new timed pool with default settings and specified timeout.

public TimedObjectPool(TimeSpan timeout)

Parameters

timeout TimeSpan

The timeout of each pooled object.

Exceptions

ArgumentOutOfRangeException

timeout is less than or equal to Zero.

Properties

Timeout

When pooled objects have not been used for a time greater than Timeout, then they will be destroyed by a cleaning task.

public TimeSpan Timeout { get; set; }

Property Value

TimeSpan

Methods

CreatePooledObject()

Creates a new pooled object, initializing its info.

protected override T CreatePooledObject()

Returns

T

A new pooled object.

CreatePooledObjectAsync(CancellationToken)

Creates a new pooled object, initializing its info.

protected override Task<T> CreatePooledObjectAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cancellation token

Returns

Task<T>

A new pooled object.