Cut CPU use and move heavy work off the UI thread
Redraws: - Merge bursts of session and bandmap events into one redraw (Coalesced). Closed Bandmap and Available windows now unsubscribe. - Grayline and Voice Keyer no longer subscribe to the session twice. - Available summary, Score table and Log rows redraw only when their contents change. Telnet lines are added in batches. - Bandmap view reuses its layout, shaped text and brushes. Grayline draws the coastlines as one cached shape. Threads: - Available, Bandmap colours, Check and Statistics do their judging and counting on the thread pool and draw the result on the UI thread. - ContestLog takes a lock in Judge and in each method that changes the log, so a background Judge cannot read the indexes mid-edit. Refresh rate: - Statistics refreshes every 30 seconds and when the QSO count changes. - Grayline refreshes at most every 15 seconds on session events. Publish with ReadyToRun to cut startup JIT time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,23 +25,40 @@ public sealed partial class GraylineWindow : RefreshableWindow
|
||||
clock = new DispatcherTimer { Interval = TimeSpan.FromMinutes(1) };
|
||||
clock.Tick += (_, _) => Refresh();
|
||||
clock.Start();
|
||||
session.Changed += WhenSessionChanged;
|
||||
Closed += (_, _) =>
|
||||
{
|
||||
clock.Stop();
|
||||
session.Changed -= WhenSessionChanged;
|
||||
later?.Cancel();
|
||||
};
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private OperatingPosition? Radio => session.Position;
|
||||
|
||||
public override void RefreshForEntry() => Refresh();
|
||||
private Throttled? later;
|
||||
|
||||
/// The map is not watched closely: a station typed or spotted shows up
|
||||
/// within fifteen seconds, and the grey line moves too slowly to see.
|
||||
public override void RefreshForEntry() => RefreshFromSession();
|
||||
|
||||
public override void RefreshFromSession()
|
||||
{
|
||||
later ??= new Throttled(TimeSpan.FromSeconds(15), Refresh);
|
||||
later.Request();
|
||||
}
|
||||
|
||||
public override void Refresh()
|
||||
{
|
||||
Map.Moment = DateTime.UtcNow;
|
||||
Map.Markers = Markers();
|
||||
DateTime now = DateTime.UtcNow;
|
||||
IReadOnlyList<MapMarker> markers = Markers();
|
||||
// the terminator moves a quarter of a degree a minute, so a redraw
|
||||
// for nothing but the clock can wait
|
||||
if (now - Map.Moment < TimeSpan.FromSeconds(30) && Map.Markers.SequenceEqual(markers))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Map.Moment = now;
|
||||
Map.Markers = markers;
|
||||
Map.InvalidateVisual();
|
||||
}
|
||||
|
||||
@@ -95,8 +112,5 @@ public sealed partial class GraylineWindow : RefreshableWindow
|
||||
private CountryLookup? Where(string call) =>
|
||||
call.Trim().Length == 0 ? null : session.Countries?.Find(call.Trim());
|
||||
|
||||
private void WhenSessionChanged(object? sender, EventArgs e) =>
|
||||
Dispatcher.UIThread.Post(Refresh);
|
||||
|
||||
private sealed record Station(string Call, double Latitude, double Longitude, IBrush Colour);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user