Timeout for xml document from internet vb.net

MichMat
MichMat used Ask the Experts™
on
Hi

I have the following code to obtain an Xml doc from the internet. It works fine. I would like to set a fairly short time out for this but cant seam to find out how. Could somene please help or suggest a different method where I can set the time out ?
Dim reader As Xml.XmlTextReader = New Xml.XmlTextReader(URL)

        ' Load data into a dataset   
        Dim GetOddsAll = New DataSet()
        
        GetOddsAll.ReadXml(reader)

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I got the code bellow to do the same thing, using webrequest and I am trying to limit the time out to 5 seconds , that is if the server dosent respond in 5 seconds I want to do something about it. However this code dosent seam to work. Do I have the time out on the right one ?

        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing

            ' Create the web request   
            request = DirectCast(WebRequest.Create(URL), HttpWebRequest)
            request.Timeout = 5000

            ' Get response   
            response = DirectCast(request.GetResponse(), HttpWebResponse)

            ' Load data into a dataset   
            GetOddsAll.ReadXml(response.GetResponseStream())
        

Open in new window

Yes,you have set the timeout correctly on webrequest.
what do you mean by code does not seem to work? do you get any exception?

Author

Commented:
No it seams like sometimes the request gets stuck for much longer then 5 seconds

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial