private void UnWatchDocumentForChanges(string fullFilePath, Action <object, FileSystemEventArgs> onChangedAction) { if (WatchedFiles.ContainsKey(fullFilePath)) { WatchedFiles[fullFilePath].Changed -= onChangedAction.Invoke; WatchedFiles[fullFilePath].EnableRaisingEvents = false; WatchedFiles[fullFilePath].Dispose(); WatchedFiles.Remove(fullFilePath); } }
private void WatchDocumentForChanges(string fullFilePath, Action <object, FileSystemEventArgs> onChangedAction) { if (!WatchedFiles.ContainsKey(fullFilePath)) { var fsw = new FileSystemWatcher(); fsw.BeginInit(); fsw.Path = Path.GetDirectoryName(fullFilePath); fsw.Filter = Path.GetFileName(fullFilePath); fsw.IncludeSubdirectories = false; fsw.NotifyFilter = NotifyFilters.LastWrite; fsw.Changed += onChangedAction.Invoke; fsw.EnableRaisingEvents = true; fsw.EndInit(); WatchedFiles.Add(fullFilePath, fsw); } }