There are 2 methods, one method depends on the other. I need to send several files to the server in parallel, which answer from the server comes first, and send it to DownloadFileAsync
method, and do the same with the rest (without waiting for all answers at once, send them (answers from the server) to DownloadFileAsync()
method, as they are received).
public async Task CompressAllFilesAsync(List<UserFile> files, string outputpath)
{
await UploadAllFilesAsync(files);
await DownloadAllFilesAsync(files, outputpath);
}
public async Task UploadAllFilesAsync(List<UserFile> files)
{
IEnumerable<Task> allTasks = files.Select(async (file, i) =>
files[i].FileLink = await UploadFileAsync(files[i])
);
await Task.WhenAll(allTasks);
}
public async Task DownloadAllFilesAsync(List<UserFile> files, string outputpath)
{
IEnumerable<Task> allTasks = files.Select((file, i) =>
DownloadFileAsync(files[i].FileLink,
Path.Combine(outputpath, $"{files[i].FileName}")
));
await Task.WhenAll(allTasks);
}
Now the program is waiting for all answers from the server (links to downloadable files) before running the DownloadAllFilesAsync()
method.