WPF: Try to fix high single core cpu usage

This commit is contained in:
genteure 2022-06-28 16:10:41 +08:00
parent 0b8cf27ce9
commit 91edf11bf8

View File

@ -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) private void ListView_SizeChanged(object sender, SizeChangedEventArgs e)
{ {
try try
@ -40,6 +43,13 @@ namespace BililiveRecorder.WPF.Controls
if (sender is not ListView listView) return; if (sender is not ListView listView) return;
if (listView.View is not GridView view) 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; var w = listView.ActualWidth - SystemParameters.VerticalScrollBarWidth - 105 - 60 - 105;
view.Columns[0].Width = 105; view.Columns[0].Width = 105;