Experimenting with WebClient.DownloadFileAsync:
public void DownloadFile(string fileUrl, string localFile)
{
using (WebClient client = new WebClient())
{
downloadingFile = true;
client.DownloadFileCompleted += client_DownloadFileCompleted;
client.DownloadFileAsync(new Uri(fileUrl), localFile);
while (downloadingFile) { };
}
}
private void client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
downloadingFile = false;
}
Problem is that the DownloadFileCompleted event is never fired, so I never set downloadingFile = false => the while loop never finishes.
Any ideas for what is going wrong?
Thanks!