Wait Till The Last File Is Downloaded
I have a code for downloading PDF files. Now I have run into a problem when I am executing next task but download of last file is not yet finished. After execution of my current co
Solution 1:
You most certainly do not want to use WebClient.DownloadFileAsync
but its newer successor WebClient.DownloadFileTaskAsync
. This would be used like this:
await DLClient.DownloadFileTaskAsync(new Uri(LinkURL), @"C:\temp\" + ExtractFilename);
This is an async
process, so your calling method will need to be async
as well. By await
ing it, you make sure that your program continues only after the download is complete (or has failed).
Solution 2:
You should load and download it asynchronously instead of blocking the current thread. When you do this it will release the thread to the caller and return back to the context only when the Load/DownLoad has been completed
htmlDoc = await new HtmlWeb().LoadAsync(src.Attributes["href"].Value);
and
await DLClient.DownloadFileAsync(new Uri(LinkURL), @"C:\temp\" + ExtractFilename);
Post a Comment for "Wait Till The Last File Is Downloaded"