Skip to content

Commit

Permalink
Closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
andreashuber-lawo committed Nov 14, 2015
1 parent 34a2bb7 commit 1c5cf49
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions Lawo.GlowAnalyzerProxy.Main/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> eventCache = new List<Event>();
private readonly ObservableCollection<Event> events = new ObservableCollection<Event>();
private readonly ReadOnlyObservableCollection<Event> readOnlyEvents;
private string listeningPort;
Expand Down Expand Up @@ -124,7 +125,7 @@ public void Start()
{
this.events.Clear();
this.IsStarted = true;
this.UpdateTimeLoop();
this.UpdateLoop();
this.ListenLoop();
}

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
});
}
Expand Down

0 comments on commit 1c5cf49

Please sign in to comment.