void UpdateLatency(ref SafeDictionary <long, float> dict, long t, ref float f, string name) { List <long> keys = new List <long>(dict.Keys); float timeAvg = 0; foreach (long key in keys) { if (key < t) { dict.Remove(key); } else { timeAvg += dict[key]; } } int count = dict.Count(); if (count > 0) { timeAvg /= count; } f = timeAvg; }