I have a problem in Asp.net C#, .net 3.5
I have the code below :
List<object> objectList = new List<object>();
foreach(var item in listItem)
{
object obj = getData (item);
objectList.add(obj);
}
Console.Write("Finish all");
Each time getData (item); fires it takes about 1s;
I want all items in ListItem to run at the same time (here is getData(item)) and then execute after foreach finishes the Console.write("Finish all").
How can I do that?
Any idea will be appreciated!
You could use the ThreadPool and ManualResetEvent:
The ThreadPool will run the task in background and the current thread will wait for all workers to finish with the ManualResetEvent.