public async Task DownloadCurrenctRates() { var currenciesWithDate = await currencyRateService.GetActiveCurrenciesWithLastDownloadedDate(); var queue = new ConcurrentQueue <CurrencyRate>(); var tasks = currenciesWithDate.Select(c => { return(Task.Run(async() => //return new Task(async () => { var uri = tradingDataService.GetCurrencyRateUri(c.Item2?.AddDays(1), c.Item1.Symbol); var currencyRates = await GetCurrencyRates(c.Item1.Symbol, uri); foreach (var rate in currencyRates) { queue.Enqueue(rate); } })); }); ////******* AlphaVantage specific code start********// ////AlphaVantage will only allow 5 call per minute //foreach (var tsk in tasks) //{ // tsk.RunSynchronously(); // if (delay.HasValue) // await Task.Delay(TimeSpan.FromSeconds(delay.Value)); //} ////******* AlphaVantage specific code end********// await Task.WhenAll(tasks); await currencyRateService.Save(queue.Select(rate => rate)); }