public virtual bool AddPooledClient(T client) { if (client == null) { return(false); } lock (LockObject) { if (Count >= MaxClients || Clients.Any(p => p == client) || ClientsInUse.ContainsKey(client.GetHashCode())) { return(false); } Clients.Enqueue(new T()); return(true); } }
public virtual bool ReturnPooledClient(T client) { if (client == null) { return(false); } lock (LockObject) { if (!ClientsInUse.ContainsKey(client.GetHashCode())) { return(false); } T clientInUse; if (!ClientsInUse.TryRemove(client.GetHashCode(), out clientInUse)) { return(false); } Clients.Enqueue(clientInUse); return(true); } }