public void RemoveWatch(string path) { ValidateArgs.NotNullOrEmpty(path, "path"); if (!String.IsNullOrEmpty(path)) { FileWatcherInfo watcherInfo; if (fileWatchers.TryGetValue(path, out watcherInfo)) { watcherInfo.Watcher.EnableRaisingEvents = false; fileWatchers.Remove(path); watcherInfo.Watcher.Changed -= OnChanged; watcherInfo.Watcher.Dispose(); watcherInfo.Watcher = null; } } }
public void AddWatch(string path) { ValidateArgs.NotNullOrEmpty(path, "path"); if (!String.IsNullOrEmpty(path)) { var directoryName = Path.GetDirectoryName(path); var fileName = Path.GetFileName(path); FileWatcherInfo watcherInfo; if (!fileWatchers.TryGetValue(path, out watcherInfo)) { watcherInfo = new FileWatcherInfo(new FileSystemWatcher(directoryName, fileName)); fileWatchers.Add(path, watcherInfo); watcherInfo.Watcher.Changed += OnChanged; watcherInfo.Watcher.EnableRaisingEvents = true; } } }