优化并行处理和代码可读性
格式化了 `data.Where` 的条件部分以提高可读性。 将并行度从 1 提升到 8 以提高性能。
This commit is contained in:
parent
83449ea2dd
commit
a10a4371ba
|
@ -196,20 +196,26 @@ public partial class MainViewModel : INotifyPropertyChanged
|
||||||
|
|
||||||
var reportDatas = new ConcurrentBag<ReportModel>();
|
var reportDatas = new ConcurrentBag<ReportModel>();
|
||||||
//foreach (var entry in data)
|
//foreach (var entry in data)
|
||||||
data.Where(it => it.OrigOcc == "OccWire" && !(it?.Properties["WireName"]?.GetDisplayValue()?.StartsWith("导线") ?? false)).AsParallel().WithDegreeOfParallelism(1).ForAll(entry =>
|
data.Where(it =>
|
||||||
{
|
it.OrigOcc == "OccWire"
|
||||||
var obj = new ReportModel();
|
&& !(it?.Properties["WireName"]?.GetDisplayValue()?.StartsWith("导线") ?? false)
|
||||||
foreach (var column in columns)
|
)
|
||||||
|
.AsParallel()
|
||||||
|
.WithDegreeOfParallelism(8)
|
||||||
|
.ForAll(entry =>
|
||||||
{
|
{
|
||||||
if (!entry.Properties.ContainsKey(column.ColumnID)) continue;
|
var obj = new ReportModel();
|
||||||
var value = entry.Properties[column.ColumnID].GetDisplayValue();
|
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);
|
var property = typeof(ReportModel).GetProperty(column.ID);
|
||||||
property?.SetValue(obj, value ?? "");
|
property?.SetValue(obj, value ?? "");
|
||||||
|
|
||||||
|
}
|
||||||
|
reportDatas.Add(obj);
|
||||||
}
|
}
|
||||||
reportDatas.Add(obj);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
return Task.FromResult(reportDatas.ToList());
|
return Task.FromResult(reportDatas.ToList());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue