Did you actually test this? The way you're using it, Parallel.ForEach
may return well before any of MyUploadMethodAsync
is completed, because of the async
lambda:
Parallel.ForEach(dirs,myParallelOptions,
async dir => { await MyUploadMethodAsync(dir) };
Parallel.ForEach
is suited for CPU-bound tasks. For IO-bound tasks, you are probably looking for something like this:
var tasks = dirs.Select(dir => MyUploadMethodAsync(dir));
await Task.WhenAll(tasks);
// or Task.WaitAll(tasks) if you need a blocking wait