Parallelizing some LINQ to XML

Posted by Lol coder on Stack Overflow See other posts from Stack Overflow or by Lol coder
Published on 2011-02-25T07:05:14Z Indexed on 2011/02/25 7:25 UTC
Read the original article Hit count: 268

How can I make this code run in parallel?

List<Crop> crops = new List<Crop>();
//Get up to 10 pages of data.
for (int i = 1; i < 10; i++)
{
    //i is basically used for paging.
    XDocument document = XDocument.Load(string.Format(url, i));

    crops.AddRange(from c in document.Descendants("CropType")
                   select new Crop
                   {
                       //The data here.
                   });
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-xml