public StreamListeners(Guid streamId) { this.streamId = streamId; this.listeners = new List <IWeakListener>(); lock (StreamsByIdLock) { StreamsById.Add(streamId, this); } }
public StreamListeners(Guid streamId) { this.streamId = streamId; this.listeners = new List <IListenerWithWeakReference>(); lock (StreamsByIdLock) { StreamsById.Add(streamId, this); StreamsByIdCapacity++; } }
public void Unlisten() { foreach (IWeakListener l in this.listeners) { l.Unlisten(); } lock (StreamsByIdLock) { StreamsById.Remove(this.streamId); } }
public void Unlisten() { foreach (IWeakListener l in this.listeners) { l.Unlisten(); } lock (StreamsByIdLock) { StreamsById.Remove(this.streamId); // Dictionary does not reclaim space after items are removed, so we will create a new one if we can reclaim a substantial amount of space if (StreamsByIdCapacity > 100 && StreamsById.Count < StreamsByIdCapacity / 2) { StreamsById = new Dictionary <Guid, StreamListeners>(StreamsById); StreamsByIdCapacity = StreamsById.Count; } } }