using System.Collections.Concurrent; namespace QFSW.QC { public class ConcurrentPool where T : class, new() { private readonly ConcurrentStack _objs; public ConcurrentPool() { _objs = new ConcurrentStack(); } public ConcurrentPool(int objCount) { _objs = new ConcurrentStack(); for (int i = 0; i < objCount; i++) { _objs.Push(new T()); } } public T GetObject() { if (_objs.TryPop(out T obj)) { return obj; } else { return new T(); } } public void Release(T obj) { _objs.Push(obj); } } }