// replaces ConcurrentDictionary which is not available in .NET 3.5 yet. using System.Collections.Generic; using System.Linq; namespace Telepathy { public class SafeDictionary { Dictionary dict = new Dictionary(); public void Add(TKey key, TValue value) { lock(dict) { dict[key] = value; } } public void Remove(TKey key) { lock(dict) { dict.Remove(key); } } // can't check .ContainsKey before Get because it might change inbetween, // so we need a TryGetValue public bool TryGetValue(TKey key, out TValue result) { lock(dict) { return dict.TryGetValue(key, out result); } } public List GetValues() { lock(dict) { return dict.Values.ToList(); } } public void Clear() { lock(dict) { dict.Clear(); } } } }