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))
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))
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...
}
You can create your own WebRequest and create an XmlReader from the response stream. See the response to this question for details:
Pass your own stream to the XmlReader.Create call. Set whatever timeout you like.
Another option is to do this
var settings = new XmlReaderSettings();
settings.XmlResolver = resolver;
// Create the reader.
XmlReader reader = XmlReader.Create("http://serverName/data/books.xml", settings);
Where the resolver
instance is a custom class that changes the url fetching behavior as described in the documentation at the link below.
© 2022 - 2024 — McMap. All rights reserved.