public void Close() { lock (this.deviceMap) { this.stopped = true; var keysToRemove = new List <string>(); foreach (KeyValuePair <string, AnnounceTimer> entry in this.deviceMap) { AnnounceTimer timer = this.deviceMap[entry.Key]; timer.Stop(); timer.Close(); keysToRemove.Add(entry.Key); } foreach (var key in keysToRemove) { this.deviceMap.Remove(key); } } }