protected override void Dispose(bool disposing) { if (disposing) { if (this.freeEvents != null) { for (int i = 0; i < this.freeEvents.Length; i++) { WaitHandle freeEvent = this.freeEvents[i]; if (freeEvent != null) { freeEvent.Close(); } } this.freeEvents = null; } if (this.inUseEvents != null) { for (int i = 0; i < this.inUseEvents.Length; i++) { WaitHandle inUseEvent = this.inUseEvents[i]; if (inUseEvent != null) { inUseEvent.Close(); } } this.inUseEvents = null; } } base.Dispose(disposing); }
// Methods public WaitableCounter(int maxCount) { if ((maxCount < 1) || (maxCount > 0x40)) { throw new ArgumentOutOfRangeException("maxCount", "must be between 1 and 64, inclusive"); } this.freeEvents = new WaitHandleArray(maxCount); this.inUseEvents = new WaitHandleArray(maxCount); for (int i = 0; i < maxCount; i++) { this.freeEvents[i] = new ManualResetEvent(true); this.inUseEvents[i] = new ManualResetEvent(false); } this.theLock = new object(); }
protected override void Dispose(bool disposing) { if (disposing) { if (this.freeEvents != null) { for (int i = 0; i < this.freeEvents.Length; i++) { WaitHandle freeEvent = this.freeEvents[i]; if (freeEvent != null) { freeEvent.Close(); } } this.freeEvents = null; } if (this.inUseEvents != null) { for (int i = 0; i < this.inUseEvents.Length; i++) { WaitHandle inUseEvent = this.inUseEvents[i]; if (inUseEvent != null) { inUseEvent.Close(); } } this.inUseEvents = null; } } base.Dispose(disposing); }
// Methods public WaitableCounter(int maxCount) { if ((maxCount < 1) || (maxCount > 0x40)) { throw new ArgumentOutOfRangeException("maxCount", "must be between 1 and 64, inclusive"); } this.freeEvents = new WaitHandleArray(maxCount); this.inUseEvents = new WaitHandleArray(maxCount); for (int i = 0; i < maxCount; i++) { this.freeEvents[i] = new ManualResetEvent(true); this.inUseEvents[i] = new ManualResetEvent(false); } this.theLock = new object(); }