From c964053e9edded74b4f93b5f9974d42fa05607b2 Mon Sep 17 00:00:00 2001 From: Bill Long Date: Wed, 24 May 2023 10:58:11 -0500 Subject: [PATCH] Enable watcher on background thread --- src/EventLogExpert/Store/EventLog/EventLogReducers.cs | 5 +++++ src/EventLogExpert/Store/EventLog/LiveLogWatcher.cs | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/EventLogExpert/Store/EventLog/EventLogReducers.cs b/src/EventLogExpert/Store/EventLog/EventLogReducers.cs index db45ca40..aa709aa3 100644 --- a/src/EventLogExpert/Store/EventLog/EventLogReducers.cs +++ b/src/EventLogExpert/Store/EventLog/EventLogReducers.cs @@ -96,6 +96,11 @@ public static EventLogState ReduceSetContinouslyUpdate(EventLogState state, Even Events = state.NewEventBuffer.Events.Concat(state.Events).ToList().AsReadOnly(), NewEventBuffer = new(new List().AsReadOnly(), false) }; + + if (state.Watcher != null && !state.Watcher.IsWatching) + { + state.Watcher.StartWatching(); + } } return newState; diff --git a/src/EventLogExpert/Store/EventLog/LiveLogWatcher.cs b/src/EventLogExpert/Store/EventLog/LiveLogWatcher.cs index e95735b0..e68a90a3 100644 --- a/src/EventLogExpert/Store/EventLog/LiveLogWatcher.cs +++ b/src/EventLogExpert/Store/EventLog/LiveLogWatcher.cs @@ -64,9 +64,15 @@ public void StartWatching() } }; - _watcher.Enabled = true; + // When the watcher is enabled, it reads all the events since the + // last bookmark. Do this on a background thread so we don't tie + // up the UI. + Task.Run(() => + { + _watcher.Enabled = true; - _debugLogger.Trace("LiveLogWatcher started watching."); + _debugLogger.Trace("LiveLogWatcher started watching."); + }); } public void StopWatching()