I am downloading some files from the internet using a WebClient
in the following way:
try
{
ManualResetEvent mr = new ManualResetEvent(fals
You should use await
and DownloadFileTaskAsync
:
try
{
using (WebClient wc = new WebClient())
{
await wc.DownloadFileTaskAsync(new Uri(string.Format("{0}/{1}", Settings1.Default.WebPhotosLocation, Path.GetFileName(f.FullName))), filePath);
}
}
catch (Exception ex)
{
//Catch my error here and handle it (display message box)
}
DownloadFileAsync uses Event-based Asynchronous Pattern, you can't catch the exception, you can get exception throw AsyncCompletedEventArgs.Error Property