Today i tried do some optimization to foreach
statement, that works on XDocument
.
Before optimization:
foreach (XElement elem in xDoc.Descendants("APSEvent").ToList())
{
//some operations
}
After optimization:
Parallel.ForEach(xDoc.Descendants("APSEvent").ToList(), elem =>
{
//same operations
});
I saw that .NET in Parallel.ForEach(...)
opened ONLY one thread! As a result the timespan of Parallel
was bigger than standard foreach
.
Why do you think .NET only opened 1 thread? Because of locking of file?
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…