public async Task DownloadAsync(InputParameters input) { using (HttpClient client = new HttpClient()) { var taskList = new List <Task <string> >(input.ReferatsAmount); var rand = new Random(); // Create and start the tasks. for (int i = 0; i < input.ReferatsAmount; i++) { var uri = uriBuilder.Build(input); var task = ProcessURLAsync(uri, client); taskList.Add(task); } foreach (var task in taskList) { var res = await task; } } }
private static InputParameters DownloadReferatsMenu() { Console.Clear(); Console.Write("Referats amount to download: "); var referatsAmount = Console.ReadLine(); //Console.WriteLine("Threads amount:"); //var threadsAmount = Console.ReadLine(); var input = new InputParameters { ReferatsAmount = Int32.Parse(referatsAmount), //ThreadsAmount = Int32.Parse(threadsAmount) }; Console.WriteLine("Enter referat category:"); while (string.IsNullOrEmpty(input.ReferatCategory)) { input.ReferatCategory = ChooseReferatCategory(); } return(input); }
public string Build(InputParameters input) { var seed = rand.Next(10000, 99999); return(BuildUrl(input.ReferatCategory, seed)); }