/// <summary> /// Event handler for the stop button. Checks to see if the wathers are enabled /// before disabling this button and enabling the start button. /// This also stops the timer. /// </summary> /// <param name="sender">The object sending the event</param> /// <param name="e">The arguments being sent by the event</param> private void btn_stop_Click(object sender, EventArgs e) { if (FileSystemEvents.WatchersEnabled()) { FileSystemEvents.EnableWatchers(false); btn_start.Enabled = true; btn_stop.Enabled = false; timer.Stop(); } }
private void FileChanged(object sender, FileSystemEventArgs e) { var relativePath = e.FullPath.Substring(node.Directory.FullName.Length).TrimStart(Path.DirectorySeparatorChar); if (relativePath.Length > 0) { var targetNode = node.EvaluatePath(relativePath.Split(Path.DirectorySeparatorChar), 0); targetNode?.NotifyFileSystemChanged(e); FileSystemEvents?.Invoke(sender, e); } }
private void ProcessEvents() { _threadStarted = true; while (true) { FileSystemEventBatchArgs batchEventsCopy = null; if (_onClosingEvent.WaitOne(SleepForward)) { break; } lock (_batchLock) { if (_clock.ElapsedMilliseconds <= MillisTimeout) { continue; } if (_batchEvents != null && _batchEvents.FileEvents.Count > 0) { batchEventsCopy = _batchEvents; _batchEvents = null; } else { continue; } } // TODO: squash events here (to avoid having duplicated events) // Invoke listeners try { SquashAndLogChanges(batchEventsCopy); // Squash can discard events (e.g if files excluded) if (batchEventsCopy.FileEvents.Count > 0) { FileSystemEvents?.Invoke(this, batchEventsCopy); } } catch (Exception ex) { Site.Error(ex, $"Unexpected error on SiteWatcher callback. Reason: {ex.GetReason()}"); } } _onClosingEvent.Reset(); }