/// <summary> /// Constructs a ConcurrentPool object. /// </summary> /// <param name="name">The name for the ConcurrentPool instance.</param> /// <param name="constructor">The <see cref="CreateInstanceDelegate"/> delegate that is used to construct the <see cref="IRecyclable"/> instance.</param> /// <param name="initialCapacity">Initial pool capacity.</param> public ConcurrentPool(string name, CreateInstanceDelegate constructor, int initialCapacity) { this.Name = name; this.Constructor = constructor; this.Releaser = new ReleaseInstanceDelegate((this as IRecycler).Release); if (initialCapacity > 0) { // Create instances for (int i = 0; i < initialCapacity; ++i) { Instances.Enqueue(CreateInstance()); } } }
/// <summary> /// Binds an <see cref="ReleaseInstanceDelegate"/> delegate which releases the <see cref="IRecyclable"/> object /// instance back to the pool. /// </summary> /// <param name="releaser">The <see cref="ReleaseInstanceDelegate"/> delegate to bind.</param> public void Bind(ReleaseInstanceDelegate releaser) { this.Release = releaser; }