/// <summary> /// Disposes all engines in this pool, and creates new engines in their place. /// </summary> public virtual void Recycle() { Recycled?.Invoke(this, null); DisposeAllEngines(); PopulateEngines(); }
public bool Recycle(T instance) { if (instance == null) { return(false); } lock (syncObject) { for (int i = 0; i < itemList.Count; ++i) { PoolItem item = itemList[i]; if (item.instance != instance) { continue; } if (!item.used) { return(true); } ++residueCount; item.used = false; item.poolItem?.OnRecycled(); Recycled?.Invoke(item.instance); return(true); } return(false); } }
public void RecycleAll() { lock (syncObject) { for (int i = 0; i < itemList.Count; ++i) { PoolItem item = itemList[i]; if (!item.used) { continue; } ++residueCount; item.used = false; item.poolItem?.OnRecycled(); Recycled?.Invoke(item.instance); } } }
/// <inheritdoc/> public virtual IEnumerable <ItemContainerInfo> RemoveRange(int startingIndex, int count) { var result = new List <ItemContainerInfo>(); if (count > 0) { for (var i = startingIndex; i < startingIndex + count; ++i) { ItemContainerInfo found; if (_containers.TryGetValue(i, out found)) { result.Add(found); } _containers.Remove(i); } var toMove = _containers.Where(x => x.Key >= startingIndex) .OrderBy(x => x.Key).ToList(); foreach (var i in toMove) { _containers.Remove(i.Key); i.Value.Index -= count; _containers.Add(i.Value.Index, i.Value); } Dematerialized?.Invoke(this, new ItemContainerEventArgs(startingIndex, result)); if (toMove.Count > 0) { var containers = toMove.Select(x => x.Value).ToList(); Recycled?.Invoke(this, new ItemContainerEventArgs(containers[0].Index, containers)); } } return(result); }
/// <summary> /// Raises the <see cref="Recycled"/> event. /// </summary> /// <param name="e">The event args.</param> protected void RaiseRecycled(ItemContainerEventArgs e) { Recycled?.Invoke(this, e); }