HTMLAgilityPack and load timeouts

I use HTMLAgilityPack in the parser that I have on the server, but I have problems with one of the sites that I process: every day around 6 in the morning they usually close their servers for maintenance, which throws the Load () method to HTMLWeb also makes my application crash. Do any of you guys have a more secure way to load a website into HTMLAgilityPack, or maybe some way to do C # error checking to prevent my application from crashing? (my C # is a little rusty). Here is my code right now:

HtmlWeb webGet = new HtmlWeb();
HtmlDocument document = webGet.Load(dealsiteLink); //The Load() method here stalls the program because it takes 1 or 2 minutes before it realizes the website is down

Thank!

+3
source share
2 answers

Just combine the call with try-catch:

HtmlWeb webGet = new HtmlWeb();

HtmlDocument document;
try
{
    document = webGet.Load(dealsiteLink); 
}
catch (WebException ex)
{
    // Logic to retry (maybe in 10 minutes) goes here
}

, - , , , try-catch , , .

, WebException - , , , . , TimeoutException.

+3

WebRequest.GetReponse - WebException, WebException, , , , HtmlAgilityPack.

http://msdn.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx#Y700

+2

All Articles