I have a following simple question - why async method doesn't wait for parallel loop completion?
public async Task<List<object>> DoSomeAsync()
{
// some async actions with streams and web requests
// ...
ConcurrentQueue<object> queue = new ConcurrentQueue<object>();
Parallel.For(1, x, async i =>
{
// a little chunk of code
// ...
queue.Enqueue(new object());
// ...
// a little chunk of code again
}
return queue.ToList(); // debugger says that this statement is executed earlier than parallel loop.
}
Do you know any ideas how can I wait for execution of parallel loop?