Jump to content
Xtreme .Net Talk

Recommended Posts

  • Moderators
Posted (edited)

The following code goes to a url, reads the source and if all is

good, it then downloads an image from that server(site).

It works well, but only 80% of the time.

 

I am always on-line, but once in a while it hangs for 30 seconds

trying to establish an internet connection.

 

Either there is something wrong in my method, or maybe I should

poll my connection prior to running the code. Any thoughts.

 

btw, I have the same logic working perfectly in VB6, using an Inet

control.

Dim sHtml As String
Dim sr As IO.StreamReader
Dim wc As New Net.WebClient()

sr = New IO.StreamReader(wc.OpenRead(m_URL))
sHtml = sr.ReadToEnd
sr.DiscardBufferedData()
sr.Close()
wc.Dispose()

'if the above succeeds then ....
Dim wc As New Net.WebClient()
wc.DownloadFile(URL_IMAGE & sDir & "/" & sName, sName)
wc.Dispose()
SetImageBox(sName)

Edited by Robby
Visit...Bassic Software
  • *Gurus*
Posted

The WebClient class is just a basic reimplementation of the WebRequest and WebResponse classes, which provide asynchronous methods that can be used to prevent application hangs.

 

I'd test your code out with other servers to see if this is an isolated issue, otherwise I'd go ahead and implement the async methods, above.

  • Moderators
Posted

It's probably not establishing a connection, but it's waiting for one.

The same as when you open IE but you're not on-line, it may wait

for a while (not always 30 seconds though).

 

I have a VB6 version which works 100% of the time, so I'm doubting it's the server.

 

The asynch is an idea, I'll give it a go.

 

Thanks.

Visit...Bassic Software
  • Moderators
Posted

I'm an idiot for not figuring it out sooner (even though I started

this project only yesterday), because in the past, any project that

used SqlClient would cause the fire-wall to prompt (allow /

disallow) after each compile, to get around this I would change

the incrementing version number to a fixed number.

 

I had assumed that once WebClient was passed the fire-wall any

subsequent request would be OK'ed as well. Live and learn :)

 

Thanks for the idea Derek, I may still use asynch approach.

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...