i am working on an asp.net mvc-4 web application.. but i am not sure what are the differences between using these 2 approaches for iteration over a list and initiate WebClient() calls :-
Approach-1
Parallel.ForEach(photos,new ParallelOptions { MaxDegreeOfParallelism = 7 }, p =>
{
ResourceAccountListInfo resourceAccountListInfo = new ResourceAccountListInfo();
WebClient wc = new WebClient();
var json = wc.DownloadString(p.url);
resourceAccountListInfo = JsonConvert.DeserializeObject<ResourceAccountListInfo>(json);
if (resourceAccountListInfo.operation.Details.CUSTOMFIELD.Count > 0)
{
List<CUSTOMFIELD> customfield = resourceAccountListInfo.operation.Details.CUSTOMFIELD.Where(a =>
a.CUSTOMFIELDLABEL.ToLower() == "name"
).ToList();
if (customfield.Count == 1)
{
PMresourcesOnly.Add(resourceAccountListInfo.operation.Details);
}
}
//code goes here
});
Approach-2
foreach (Photo p in photos)
{
Task.Factory.StartNew(() =>
{
ResourceAccountListInfo resourceAccountListInfo = new ResourceAccountListInfo();
WebClient wc = new WebClient();
var json = wc.DownloadString(p.url);
resourceAccountListInfo = JsonConvert.DeserializeObject<ResourceAccountListInfo>(json);
if (resourceAccountListInfo.operation.Details.CUSTOMFIELD.Count > 0)
{
List<CUSTOMFIELD> customfield = resourceAccountListInfo.operation.Details.CUSTOMFIELD.Where(a =>
a.CUSTOMFIELDLABEL.ToLower() == "name"
).ToList();
if (customfield.Count == 1)
{
PMresourcesOnly.Add(resourceAccountListInfo.operation.Details);
}
}
//code goes here
});
}
thanks