private void OnChanged(object sender, FileSystemEventArgs e) { try { if (!string.IsNullOrEmpty(WatchFilter) && (WatchFilter.Contains(",") || WatchFilter.Contains("|"))) { bool cont = false; var array = WatchFilter.Split(new Char[] { ',', '|' }); foreach (var ext in array) { if (PatternMatcher.FitsMask(e.FullPath, ext)) { cont = true; } } if (!cont) { return; } } TimeSpan timepassed = DateTime.Now - lastTriggered; if (timepassed.Milliseconds < 100) { return; } lastTriggered = DateTime.Now; var _e = new DetectorEvent(e.FullPath); OnDetector?.Invoke(this, _e, EventArgs.Empty); } catch (Exception ex) { Log.Error(ex.ToString()); } }
public void Start() { try { watcher.Path = Watchpath; watcher.NotifyFilter = NotifyFilters.LastWrite; if (!string.IsNullOrEmpty(WatchFilter) && (WatchFilter.Contains(",") || WatchFilter.Contains("|"))) { watcher.Filter = "*"; } else { watcher.Filter = WatchFilter; } watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.EnableRaisingEvents = true; watcher.IncludeSubdirectories = IncludeSubdirectories; } catch (Exception ex) { Log.Error(ex.ToString()); } }