Im trying to run a list of HttpRequest tasks parallelly (not just asynchronously), and Only after all tasks are completed- output results. But when i run my code it doesnt wait but run the whole program and then later on i see the completion of tasks(thats when responses come). why ? how do i make the writeline in the end, Wait till all tasks are done ? (and no im not looking for WhenAll(); that isn't parallel (parallelly the requests finish faster since they're all starting parallelly without awaiting each other; which is good. but again i need to print results Only AFTER they're all complete; which is where im stuck at how to do it
Stopwatch stopWatch = new Stopwatch();
List<Task> tasks = new List<Task>();
foreach (var item in uriRequests)
{
tasks.Add(HttpRequestAsync(item));
}
stopWatch.Start();
Parallel.ForEach(tasks, task =>
{
task.ConfigureAwait(false);
});
stopWatch.Stop();
//====================i want to wait until the tasks are completed-only then output the next code (writeline) but it doesnt happen that way
Console.WriteLine($"Finish Executing within {stopWatch.Elapsed}. Requests Completed: {completedRequests}");