I'm using WebClient.DownloadFileAsync
to obtain a batch of files. However some files turn out to be incomplete, and there is no exception.
My question is, how to flag when a downloaded file is not complete? There is no md5 checksum to verify.
Code snippet is:
using (WebClient client = new WebClient())
{
Uri sUri = new Uri(sFileLink);
client.DownloadFileAsync(sUri, myPath);
}
You're disposing of the client before it's finished downloading. Don't do that.
You should only dispose of the WebClient
when either there's an error or it's completed, which you'd discover by the events that WebClient
raises (or using DownloadFileTaskAsync
in .NET 4.5, and awaiting the resulting task).