Multi threaded Application

From .NET 4.0 the simplest way to do this is:

var listOfSomething = new PopulateListOfSomething();
var tasks = new Task[listOfSomething.Count];

for (int i = 0; i < listOfSomething.Count; i++)
{
    var someService = new SomeService(listOfSomething[i]);
    tasks[i] = Task.Factory.StartNew(() => someService.Go());
}

Task.WaitAll(tasks);

References

Leave a Reply