/// <summary> /// ObjectPool constructor. /// </summary> /// <param name="MinItems">Minimum number of items in pool. The constructor will create these items, calling OnCreateHandler if supplied.</param> /// <param name="MaxItems">Maximum number of items in pool. Acquire() will return default values when this threshold is reached.</param> /// <param name="ItemLifeSpanMinutes">The longest an item should exist. Items that exceed their lifespan are removed and cleaned up.</param> /// <param name="OnCreateHandler">Event handler to call when a new item is created for the pool.</param> /// <param name="OnCleanUpHandler">Event handler to call when an expired item is removed from the pool.</param> public ObjectPool(int MinItems, int MaxItems, int ItemLifeSpanMinutes, OnCreateDelegate OnCreateHandler = null, OnCleanUpDelegate OnCleanUpHandler = null, OnAcquireDelegate OnAcquireHandler = null) { ShuttingDown = false; items = new ConcurrentDictionary <T, PoolItem <T> >(); OnCreate = OnCreateHandler; OnCleanUp = OnCleanUpHandler; OnAcquire = OnAcquireHandler; this.MinItems = MinItems; this.MaxItems = MaxItems; this.ItemLifeSpanMinutes = ItemLifeSpanMinutes; for (int i = 0; i < MinItems; i++) { T newItem = new T(); if (OnCreate != null) { OnCreate(ref newItem); } items[newItem] = new PoolItem <T>(newItem); ItemsAllocated++; } }
public Task <IAsyncDisposable> OnCreate(OnCreateDelegate handler) { return(InnerSubscribe(handler, x => x.OnCreate(default(long), default(SubscriptionDetails)))); }