Some sample code may be helpful:
class Semaphore {
public Semaphore(int maxCount, int initialCount) {
_maxCount = maxCount;
_currentCount = currentCount;
}
public void Acquire() {
lock(this) {
while (_currentCount >= _maxCount) {
Monitor.Wait(this);
}
++_currentCount;
}
}
public void Release(int count) {
lock(this) {
_currentCount -= count;
Monitor.PulseAll(this);
}
}
private int _maxCount;
private int _currentCount;
}
---------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. Copyright 2001 Microsoft Corporation. All
rights reserved.