public async Task DownloadFile(string urlAddress, string location)
{
Stopwatch sw = new Stopwatch();
using (WebClient webClient = new WebClient())
{
webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0 Chrome");
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(((sender, e) => await Completed(sender, e, sw)));
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler((sender, e) => ProgressChanged(sender, e, sw));
Uri URL = new Uri(urlAddress);
sw.Start();
try
{
await webClient.DownloadFileTaskAsync(URL, location);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
getting error on the line :
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(((sender, e) => await Completed(sender, e, sw)));
on the part :
await Completed(sender, e, sw)
'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.
not sure where and how to mark it as async.