0
for (int i = 0; i < urls.Count; i++)
                {
                    tracker.NewFile();

                    if (urls[i].Contains("Radar"))
                    {
                        lblStatus.Text = "Downloading Radar Images";

                        downloadedImageName = radarFolderImagesDownload + "\\radarImage" + radCounter + ".gif";

                        radCounter++;
                        try
                        {
                            await client.DownloadFileTaskAsync(new Uri(urls[i]), radarFolderImagesDownload + "\\radarImage" + radCounter + ".gif");
                        }
                        catch (WebException ex)
                        {
                            Logger.Write($"Downloading {urls[i]} failed. {ex.Message}");
                        }
                        catch (InvalidOperationException)
                        {
                            Logger.Write($"Saving {urls[i]} to {radarFolderImagesDownload + "\\radarImage" + radCounter + ".gif"} failed. File is in use.");
                        }
                }

i used a break point and first it's getting to the line with the DownloadFileTaskAsync and then it's getting to the catch.

i want that if it's getting to the catch don't download and save empty image just continue to the next link in the urls list.

Benzi Avrumi
  • 937
  • 1
  • 8
  • 24
  • have a look at this post https://stackoverflow.com/questions/26534980/why-in-my-webclient-downloadfileasync-method-downloading-an-empty-file – avikalb Sep 04 '22 at 23:29
  • Just an FYI: Note that using WebClient is discouraged and HttpClient should be used instead. Source: The horses mouth, aka the official documentation for WebClient https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient?view=net-6.0#remarks –  Sep 04 '22 at 23:43

0 Answers0