I'm downloading 10 images at the same time async, but in the 2nd photo usually the error that the image is in use.
The process can not access the file because it is being used by another process.
I already think it's strange, because the old code that moved the images after the download was already removed, that is, I'm not doing anything beyond the download, so I should not give this error.
My code looks like this:
public static async Task DownloadImgAsync(IEnumerable<FotosProduto> urls, int id)
{
//recebe uma lista com 10 urls para download
var urlTasks = urls.Select((url, index) =>
{
using (var wc = new WebClient())
{
var urlTratada = url.Url.Replace(" ", "").Replace("\n", "");
//garantindo que a url está correta
var path = Caminhos.FolderImg + url.FileNameFinal;
//aqui só recupero a pasta default das minhas imagens + o nome final da foto
var downloadTask = wc.DownloadFileTaskAsync(new Uri(urlTratada), path);
//insere o processo na task de download
wc.Dispose(); //redudante pelo using, mas ainda sim pra tentar evitar o erro.
return downloadTask;
}
});
await Task.WhenAll(urlTasks);
}
See that I have already put it with using
and for disclaimer I still call dispose
, however it always returns that the image is in use. how?
NOTE: This function is called for each product, usually I have a large list of products running eg 1000mil products and each product 10 images.
Other questions from me regarding the same project: