internal void SetClientAmount(uint amount) { lockObject.EnterWriteLock(); for (int i = 0; i < amount; i++) { int newID = databaseClients.Count + 1; DatabaseClientOld newClient = new DatabaseClientOld((uint)newID, connectionString, this); databaseClients.Add(newID, newClient); newClient.Connect(); } lockObject.ExitWriteLock(); }
internal DatabaseClientOld GetClient() { lockObject.EnterReadLock(); DatabaseClientOld returnClient = null; foreach (DatabaseClientOld client in databaseClients.Values) { if (client.isWorking) { continue; } if (client.State == ConnectionState.Closed) { client.Connect(); } if (client.State == ConnectionState.Open) { returnClient = client; returnClient.UpdateLastActivity(); break; } } lockObject.ExitReadLock(); if (returnClient != null) { return(returnClient); } if (databaseClients.Count < databaseSettings.maxPoolSize) { lockObject.EnterWriteLock(); int newID = databaseClients.Count + 1; DatabaseClientOld newClient = new DatabaseClientOld((uint)newID, connectionString, this); databaseClients.Add(newID, newClient); newClient.Connect(); newClient.UpdateLastActivity(); lockObject.ExitWriteLock(); return(newClient); } DatabaseClientOld anonymousClient = new DatabaseClientOld(0, connectionString, this); anonymousClient.Connect(); anonymousClient.UpdateLastActivity(); return(anonymousClient); }
internal DatabaseClientOld GetClient() { lockObject.EnterReadLock(); DatabaseClientOld returnClient = null; foreach (DatabaseClientOld client in databaseClients.Values) { if (client.isWorking) continue; if (client.State == ConnectionState.Closed) client.Connect(); if (client.State == ConnectionState.Open) { returnClient = client; returnClient.UpdateLastActivity(); break; } } lockObject.ExitReadLock(); if (returnClient != null) return returnClient; if (databaseClients.Count < databaseSettings.maxPoolSize) { lockObject.EnterWriteLock(); int newID = databaseClients.Count + 1; DatabaseClientOld newClient = new DatabaseClientOld((uint)newID, connectionString, this); databaseClients.Add(newID, newClient); newClient.Connect(); newClient.UpdateLastActivity(); lockObject.ExitWriteLock(); return newClient; } DatabaseClientOld anonymousClient = new DatabaseClientOld(0, connectionString, this); anonymousClient.Connect(); anonymousClient.UpdateLastActivity(); return anonymousClient; }