private void OnUnblockTimer() { bool? Unblock = null; List <string> EntryToForget = new List <string>(); List <string> EntryToRemove = new List <string>(); lock (CreateFileTable) { foreach (KeyValuePair <string, Stopwatch> Entry in UnlockedFileTable) { string Path = Entry.Key; TimeSpan Elapsed = Entry.Value.Elapsed; if (Elapsed >= MinElapsedTimeForForget) { AddLog($"Forgetting {Path} (after {(int)Elapsed.TotalMilliseconds})"); EntryToForget.Add(Path); } } foreach (string Path in EntryToForget) { UnlockedFileTable.Remove(Path); } foreach (KeyValuePair <string, Stopwatch> Entry in CreateFileTable) { string Path = Entry.Key; TimeSpan Elapsed = Entry.Value.Elapsed; if (Elapsed >= MinElapsedTimeForUnblock) { if (!Unblock.HasValue) { Unblock = IsUnblocking; } if (Unblock.Value) { EntryToRemove.Add(Path); if (!UnlockedFileTable.ContainsKey(Path)) { AddLog($"Unblocking {Path} (after {(int)Elapsed.TotalMilliseconds})"); UnblockFile(Path); Stopwatch NewWatch = new Stopwatch(); UnlockedFileTable.Add(Path, NewWatch); NewWatch.Start(); } } } } foreach (string Path in EntryToRemove) { CreateFileTable.Remove(Path); } } }
private void OnChanged(object sender, FileSystemEventArgs e) { lock (CreateFileTable) { AddLog("OnChanged " + e.FullPath + ", " + e.ChangeType); if (!CreateFileTable.ContainsKey(e.FullPath)) { Stopwatch NewWatch = new Stopwatch(); CreateFileTable.Add(e.FullPath, NewWatch); NewWatch.Start(); } else { Stopwatch Watch = CreateFileTable[e.FullPath]; Watch.Restart(); } } }