I Have a function that looks like this:
public async Task<decimal> GoToWeb(string Sym){}
what's the best way to call it over a list of strings?
Here's an article from MSDN on using async-await
to process multilpe tasks in parallel. And here's another that specifically addresses a collection of tasks.
In short, you can do one of the following:
Start all of your tasks and then await
each of them. They will all run in parallel and your program will continue once they all complete.
Put your tasks into a collection and then use await
Task.WhenAll
to wait for multiple tasks.
An example of the second method would be as follows:
List<string> Syms = ... // Create your list of strings
IEnumerable<Task<decimal>> tasks = from Sym in Syms select GoToWeb(Sym);
decimal[] results = await Task.WhenAll(tasks);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With