Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XMLTextReader.Read and WebClient.Read take ages...

Status
Not open for further replies.

Ploper001

Technical User
Oct 5, 2006
286
GB
I'm sure this didn't used to take as long, but for some reason this process currently takes between 15-30s, despite the fact that the webpage it is searching through loads instantly in IE7:

Dim IPAddress As String
Dim XMLReader As XmlTextReader = New XmlTextReader(" Dim WebClient As New WebClient
Dim WebStream As Stream
Dim WebStreamURLs As String() = {" " Dim StreamText As String
Dim StreamBuffer As Byte() = New Byte(256 - 1) {}


If XMLReader.CanResolveEntity Then
While XMLReader.ReadToFollowing("ip")
IPAddress = XMLReader.ReadElementString()
If IsValidIPAddress(IPAddress) Then Return IPAddress
End While
End If

For Each URL As String In WebStreamURLs
Try
WebStream = WebClient.OpenRead(URL)
If WebStream.CanRead Then
WebStream.Read(StreamBuffer, 0, 256)
StreamText = Encoding.ASCII.GetString(StreamBuffer, 0, 256)
Select Case URL
Case WebStreamURLs(0)
StreamText = StreamText.Substring((StreamText.IndexOf("<TITLE>") + 24), 15)
If (StreamText.IndexOf("<") <> (-1)) Then
StreamText = StreamText.Split("<")(0)
End If
Case WebStreamURLs(1)
StreamText = StreamText.Substring(0, StreamText.IndexOf(Chr(0)))
End Select
If IsValidIPAddress(StreamText) Then Return StreamText
End If
Catch Ex As Exception
Err.Clear()
End Try
Next


Lines in bold take 15-30s the first time the program is run. If you run the program shortly afterwards, it'll take <3s. Is there any reason why this seemingly simple and quick process would take so long?! I mean, the XML sites it's searching aren't exactly big!!

Any help appreciated!
 
Well I tried it by downloading the XML file first, and then searching it, and it didn't change the time much.

So basically...why is .NET so slow at any form of downloading?? This is .NET 2005 Express btw!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top