static void RetryTimer_Elapsed(object sender, ElapsedEventArgs e) { RetryWatch[] queue; lock (RetryQueue) { queue = RetryQueue.Values.ToArray(); } queue = queue.Where(rw => DoRetry(rw)).ToArray(); lock (RetryQueue) { foreach (RetryWatch resolved in queue) { RetryQueue.Remove(resolved.eventArgs); } } }
static void Retry(FileSystemEventArgs e, FileSystemWatcher sender) { lock (RetryQueue) { if (RetryQueue.ContainsKey(e)) { RetryQueue[e].retries--; if (RetryQueue[e].retries <= 0) { RetryQueue.Remove(e); } } else { RetryQueue.Add(e, new RetryWatch(sender, e)); } } RetryTimer.Enabled = true; }