diff --git a/Lawo.GlowAnalyzerProxy.Main/MainWindowViewModel.cs b/Lawo.GlowAnalyzerProxy.Main/MainWindowViewModel.cs index 71ffb340..a6fca2fa 100644 --- a/Lawo.GlowAnalyzerProxy.Main/MainWindowViewModel.cs +++ b/Lawo.GlowAnalyzerProxy.Main/MainWindowViewModel.cs @@ -42,6 +42,7 @@ internal sealed class MainWindowViewModel : NotifyPropertyChanged, IDataErrorInf private readonly Settings settings; private readonly ConnectionViewModel consumerConnection; private readonly ConnectionViewModel providerConnection; + private readonly List eventCache = new List(); private readonly ObservableCollection events = new ObservableCollection(); private readonly ReadOnlyObservableCollection readOnlyEvents; private string listeningPort; @@ -124,7 +125,7 @@ public void Start() { this.events.Clear(); this.IsStarted = true; - this.UpdateTimeLoop(); + this.UpdateLoop(); this.ListenLoop(); } @@ -299,12 +300,29 @@ internal DateTime Now //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - private async void UpdateTimeLoop() + private async void UpdateLoop() { while (this.IsStarted) { this.Now = DateTime.UtcNow; - await Task.Delay(500); + + // The following is necessary because adding events one by one did only scale to roughly 100 events + // per second, due to high CPU load, see #12. + foreach (var evt in eventCache) + { + this.events.Add(evt); + } + + eventCache.Clear(); + var handler = this.ScrollEventIntoView; + + if ((this.events.Count > 0) && + this.AutoScrollToMostRecentEvent.GetValueOrDefault() && (handler != null)) + { + handler(this, new ScrollEventIntoViewEventArgs(this.events[this.events.Count - 1])); + } + + await Task.Delay(250); } } @@ -506,14 +524,7 @@ await this.logQueue.Enqueue( logInfo.Path, logStartPos, logLength); - this.events.Add(evt); - - var handler = this.ScrollEventIntoView; - - if (this.AutoScrollToMostRecentEvent.GetValueOrDefault() && (handler != null)) - { - handler(this, new ScrollEventIntoViewEventArgs(evt)); - } + this.eventCache.Add(evt); } }); }