tags:

views:

6

answers:

0

Hey all

well basically I'm asynchronously downloading some string all from the same web uri, just imagine different pages.

WebClient client = new WebClient();
client.DownloadStringCompleted += (client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri(yahooAddress));

Anyway the service isn't great, and about 10% of request fail as a result. Essentially I wanted to store the failed Uri so they can be re-visited in hope to get the data.

Here's my complete method:

static void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XDocument xDoc = new XDocument();


            if(e.Error != null)
            {
                throw new WebException();
            }

            xDoc = XDocument.Parse(e.Result);

//other stuff, not bothering posted
}

Now I know that if a web exception was thrown, I could use the Response.Status or a similar property to retrieve the uri, but obviously that would involve trying to create a scenario to manually make my application throw exceptions which doesn't sound like great practice.

Advice appreciated.