From a10a4371bac25b826f151ff5dcdf0530f0ed7e5d Mon Sep 17 00:00:00 2001 From: lihanbo Date: Fri, 8 Nov 2024 10:21:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B9=B6=E8=A1=8C=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=92=8C=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 格式化了 `data.Where` 的条件部分以提高可读性。 将并行度从 1 提升到 8 以提高性能。 --- .../ViewModel/MainViewModel.cs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs index 96e0bd6..50339a3 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs @@ -196,20 +196,26 @@ public partial class MainViewModel : INotifyPropertyChanged var reportDatas = new ConcurrentBag(); //foreach (var entry in data) - data.Where(it => it.OrigOcc == "OccWire" && !(it?.Properties["WireName"]?.GetDisplayValue()?.StartsWith("导线") ?? false)).AsParallel().WithDegreeOfParallelism(1).ForAll(entry => - { - var obj = new ReportModel(); - foreach (var column in columns) + data.Where(it => + it.OrigOcc == "OccWire" + && !(it?.Properties["WireName"]?.GetDisplayValue()?.StartsWith("导线") ?? false) + ) + .AsParallel() + .WithDegreeOfParallelism(8) + .ForAll(entry => { - if (!entry.Properties.ContainsKey(column.ColumnID)) continue; - var value = entry.Properties[column.ColumnID].GetDisplayValue(); + var obj = new ReportModel(); + foreach (var column in columns) + { + if (!entry.Properties.ContainsKey(column.ColumnID)) continue; + var value = entry.Properties[column.ColumnID].GetDisplayValue(); - var property = typeof(ReportModel).GetProperty(column.ID); - property?.SetValue(obj, value ?? ""); + var property = typeof(ReportModel).GetProperty(column.ID); + property?.SetValue(obj, value ?? ""); + } + reportDatas.Add(obj); } - reportDatas.Add(obj); - } ); return Task.FromResult(reportDatas.ToList()); }