void CallChanged(FMWEventArgs args) { List <EventHandler> calls = null; if (FileModified != null) { try { calls = FileModified.GetInvocationList().Cast <EventHandler>().ToList(); } catch { } } foreach (EventHandler c in calls) { try { c(this, args); } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("STEM.Sys.IO.CallChanged", ex, EventLog.EventLogEntryType.Error); } } }
protected override void Execute(ThreadPool owner) { try { List <string> found = new List <string>(); List <FMWEventArgs> changed = new List <FMWEventArgs>(); foreach (string file in STEM.Sys.IO.Directory.STEM_GetFiles(Directory, FileFilter, DirectoryFilter, Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly, true)) { try { found.Add(file); DateTime lwt = System.IO.File.GetLastWriteTimeUtc(file); lock (_Watching) { if (_Watching.ContainsKey(file)) { FMWEventArgs a = _Watching[file]; if (a.CurrentModificationTimeUtc != lwt) { a.PreviousModificationTimeUtc = a.CurrentModificationTimeUtc; a.CurrentModificationTimeUtc = lwt; changed.Add(a); } } else { FMWEventArgs a = new FMWEventArgs { File = file, PreviousModificationTimeUtc = DateTime.MinValue, CurrentModificationTimeUtc = lwt }; _Watching.Add(file, a); changed.Add(a); } } } catch { } } lock (_Watching) foreach (string file in _Watching.Keys.Except(found)) { if (!System.IO.File.Exists(file)) { FMWEventArgs a = _Watching[file]; a.PreviousModificationTimeUtc = a.CurrentModificationTimeUtc; a.CurrentModificationTimeUtc = DateTime.MinValue; changed.Add(a); } } foreach (FMWEventArgs a in changed) { CallChanged(a); } } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("STEM.Sys.IO.FileModificationWatcher.Execute", ex, EventLog.EventLogEntryType.Error); } }