private void OnFileEvent(object sender, FileEventArgs e) { RemoveInvalidClients(); using (AutoLock.LockToRead(_clients.Lock, 5000)) { foreach (Client client in _clients.Values) { ThreadPool.QueueUserWorkItem(NotifyThreadProc, NotifyThreadStateInfo.Create(client, e)); } } }
private void RemoveInvalidClients() { List <Guid> removeClientList = new List <Guid>(); using (AutoLock.LockToRead(_clients.Lock, 5000)) { foreach (Client client in _clients.Values) { if (!client.IsValid) { removeClientList.Add(client.Id); } } } foreach (Guid id in removeClientList) { if (_clients.ContainsKey(id)) { _clients.Remove(id); } } }