From 91edf11bf8c096a4dd8f7dbf9f0624ec24a85a38 Mon Sep 17 00:00:00 2001 From: genteure Date: Tue, 28 Jun 2022 16:10:41 +0800 Subject: [PATCH] WPF: Try to fix high single core cpu usage --- BililiveRecorder.WPF/Controls/LogPanel.xaml.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BililiveRecorder.WPF/Controls/LogPanel.xaml.cs b/BililiveRecorder.WPF/Controls/LogPanel.xaml.cs index 4b0f60f..bbc6392 100644 --- a/BililiveRecorder.WPF/Controls/LogPanel.xaml.cs +++ b/BililiveRecorder.WPF/Controls/LogPanel.xaml.cs @@ -33,6 +33,9 @@ namespace BililiveRecorder.WPF.Controls { } } + private static readonly TimeSpan OneSecond = TimeSpan.FromSeconds(1); + private DateTimeOffset lastSizeChanged = DateTimeOffset.MinValue; + private void ListView_SizeChanged(object sender, SizeChangedEventArgs e) { try @@ -40,6 +43,13 @@ namespace BililiveRecorder.WPF.Controls if (sender is not ListView listView) return; if (listView.View is not GridView view) return; + var now = DateTimeOffset.Now; + + if (now - this.lastSizeChanged < OneSecond) + return; + + this.lastSizeChanged = now; + var w = listView.ActualWidth - SystemParameters.VerticalScrollBarWidth - 105 - 60 - 105; view.Columns[0].Width = 105;