I've got a loop like this
ICollection<Data> GetData()
{
ICollection<Data> result = new List<Data>()
foreach (var item in aCollection)
item.AddData(result);
return result;
}
and I now need this to be executed in parallel instead iteratively. My first attempt was to do soemthing like this
ICollection<Data> GetData()
{
ICollection<Data> result = new SynchronizedCollection<Data>()
foreach (var item in aCollection)
new Thread(delegate() { item.AddData(result); }).Start();
return result;
}
but I need a way to wait for all the data to be added before I return the result.
What would be the simplest way to do this?
Edit: That AddData
will call across a network. In the collection usually are up to a few dozen entries.