I have the following code:
foreach (XmlNode xn in xnList)
{
String NAME = xn["name"].InnerText;
}
I want to launch each loop in parallel. How can I do this? I thought that I could use the following method, but I can’t figure out the way to make it work:
ParallelOptions parOptions = new ParallelOptions();
parOptions.MaxDegreeOfParallelism = 4; //only up to 5 threads allowed.
Parallel.ForEach(xnList.AsEnumerable(), parOptions, xn=>
{
String NAME = xn["name"].InnerText;
}
I came up with this solution: