static void _Work() { List <string> addedFile = new List <string>(); foreach (Project project in ProjectManager.Projects) { List <string> t = new List <string>(); foreach (string file in project.Root.SubFiles2) { var tasks = _GetTask(file); if (tasks != null && tasks.Count > 0) { t.Add(file); _Cache[file] = tasks; } // Unload items during loading if (ProjectManager.GetProjectIndex(project) == -1) { foreach (string f in t) { if (_Cache.ContainsKey(file)) { _Cache.Remove(file); } } t.Clear(); break; } } if (t.Count > 0) { addedFile.AddRange(t); } } if (addedFile.Count > 0 && TaskChanged != null) { foreach (string file in addedFile) { TaskChanged(file, _Cache[file]); } } while (true) { DateTime current = DateTime.Now; try { Dictionary <string, int> r = null; Dictionary <string, int> u = null; lock (typeof(TaskUpdater)) { r = _RemovedFiles; _RemovedFiles = new Dictionary <string, int>(); u = _UpdatedFiles; _UpdatedFiles = new Dictionary <string, int>(); } foreach (string file in r.Keys) { if (_Cache.ContainsKey(file)) { _Cache.Remove(file); } } List <string> updatedFiles = new List <string>(); foreach (string file in u.Keys) { var tasks = _GetTask(file); if (_Cache.ContainsKey(file)) { var oldTasks = _Cache[file]; if (!_IsEqual(tasks, oldTasks)) { _Cache[file] = tasks; updatedFiles.Add(file); } } else { _Cache[file] = _GetTask(file); updatedFiles.Add(file); } } if (TaskChanged != null) { foreach (string file in r.Keys) { TaskChanged(file, null); } foreach (string file in updatedFiles) { TaskChanged(file, _Cache[file]); } } } catch { } var d = DateTime.Now - current; if (d.TotalSeconds < 1) { Thread.Sleep((int)(1 - d.TotalSeconds) * 1000); } } }