I have a method which is run n times with different parameters, simplified:
foreach(var param in params)
ValueList.Add(SomeMethod(param));
I would like to do this:
foreach(var param in params)
TaskList.Add(SomeMethodAsync(param));
foreach(var task in TaskList)
ValueList.Add(await task);
async Task<SomeValue> SomeMethodAsync(SomeParam p)
{
//What to do here
//To make this call async
return SomeMethod(p);
}
How do I have to modify the current Method to apply the async functionality? The SomeMethod does not use any framework-functions that provide async; it is fully synchronous.
To describe it in different words: I want n tasks of this method to run asynchronously/simultaneously using the new async/await keywords.
foreachloop can be replaced withvar valueList = await Task.WhenAll(taskList);.Parrallel.ForEach,Jobs.AsParallel.Select(x => SomeMethod(x))or when I use Tasks. (actually Tasks took a little bit longer than the rest) The sum of time is well above the individual operation timeout time.