Why isn't Parallel.ForEach running multiple threads?

后端 未结 6 2029
离开以前
离开以前 2020-12-15 17:24

Today i tried do some optimization to foreach statement, that works on XDocument.

Before optimization:

foreach (XElement el         


        
6条回答
  •  情深已故
    2020-12-15 18:05

    Yes exactly, Document.Load(...) locks the file and due to resource contention between threads, TPL is unable to use the power of multiple threads. Try to load the XML into a Stream and then use Parallel.For(...).

提交回复
热议问题