Last active
September 4, 2018 15:50
-
-
Save alimozdemir/da0399b4ea76a1fd802c02d342972559 to your computer and use it in GitHub Desktop.
Object Pool example usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void BasicExample() | |
{ | |
Console.WriteLine("Havuzun boyutu {0}", ClientPool.Instance.Size); | |
Console.WriteLine("Client sınıfı ediniyoruz."); | |
var client1 = ClientPool.Instance.AcquireObject(); | |
client1.Connect(); | |
Console.WriteLine("Client'ı geri bırakıyoruz"); | |
if (client1 != null) | |
ClientPool.Instance.ReleaseObject(client1); | |
var clients = new List<Client>(); | |
for (int i = 0; i < ClientPool.Instance.Size; i++) | |
{ | |
clients.Add(ClientPool.Instance.AcquireObject()); | |
} | |
Console.WriteLine("Uygun olan tüm Client nesneleri listeye eklendi."); | |
var nullClient = ClientPool.Instance.AcquireObject(); | |
if (nullClient == null) | |
Console.WriteLine("Daha fazla Client sınıfı bulunmamaktadır."); | |
Console.WriteLine("Havuzun boyutunu arttırıyoruz"); | |
ClientPool.Instance.IncreaseSize(); | |
Console.WriteLine("Yeni bir Client sınıfı ediniyoruz."); | |
var newClient = ClientPool.Instance.AcquireObject(); | |
newClient.Connect(); | |
Console.WriteLine("Edindiğimiz sınıfı geri veriyoruz."); | |
if (newClient != null) | |
ClientPool.Instance.ReleaseObject(newClient); | |
Console.WriteLine("Listedeki tüm Client sınıflarını geri bırakıyoruz."); | |
foreach (var item in clients) | |
ClientPool.Instance.ReleaseObject(item); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment