Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify timeout for XmlReader?

I am reading rss with xml reader.

And when url is bad it takes 60 seconds to fail for it. How i can specify timeout?

using (XmlReader reader = XmlReader.Create(url, settings))
like image 804
st78 Avatar asked Jan 26 '11 19:01

st78


2 Answers

I don't know if it's possible to change the XmlReader timeout, but maybe you can do something different:

Use WebRequest to get the xml (this does have a Timeout property) and feed XmlReader this xml after you have received it:

WebRequest request = WebRequest.Create(url);
request.Timeout = 5000;

using (WebResponse response = request.GetResponse())
using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
{
    // Blah blah...
}
like image 100
Scott Avatar answered Nov 04 '22 00:11

Scott


You can create your own WebRequest and create an XmlReader from the response stream. See the response to this question for details:

Prevent or handle time out with XmlReader.Create(uri)

like image 44
Andreas Vendel Avatar answered Nov 04 '22 00:11

Andreas Vendel