static bool RegisterDirectoriesInTree_NoLock(object id, HashSet <FilePath> set) { Debug.Assert(Monitor.IsEntered(watchers)); // Remove paths subscribed for this id. bool modified = false; if (monitoredDirectories.TryGetValue(id, out var oldDirectories)) { HashSet <FilePath> toRemove = null; if (set != null) { toRemove = new HashSet <FilePath> (oldDirectories); // Remove the old ones which are not in the new set. toRemove.ExceptWith(set); } else { toRemove = oldDirectories; } foreach (var dir in toRemove) { var node = tree.RemoveNode(dir, id); bool wasRemoved = node != null && !node.IsLive; modified |= wasRemoved; } } // Remove the current registered directories monitoredDirectories.Remove(id); if (set == null) { return(modified); } HashSet <FilePath> toAdd = null; if (oldDirectories != null) { toAdd = new HashSet <FilePath> (set); toAdd.ExceptWith(oldDirectories); } else { toAdd = set; } // Apply new ones if we have any if (set.Count > 0) { monitoredDirectories [id] = set; foreach (var path in toAdd) { tree.AddNode(path, id, out bool isNew); // We have only modified the tree if there is any new pathtree node item added modified |= isNew; } } return(modified); }