The count on semaphore decremented each time when a thread enter and incremented when a thread exit. When the count is zero it means no slot is empty for new thread and new thread have to wait until other thread released. When all thread are released than it have maximum value specified at time on creation.
Semaphore semaphoreObj = new Semaphore(initialCount: 0, maximumCount: 5);First parameter specify how many slot are available at the time of object instantiated. The second parameter specify the maximum number of slots available. If you want to reserve some slots fo calling thread you can put first number smaller than second one. To make available all slots you should have both parameter same.
bool isSignalled = semaphoreObject.WaitOne(TimeSpan.FromSeconds(4));Time interval specify, if there is no slot available than the thread will wait upto given time. If calling thread does not receive any signal within given time than it return false. If it receive signal than return true.