Moderators Robby Posted April 6, 2003 Moderators Posted April 6, 2003 (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 April 6, 2003 by Robby Quote Visit...Bassic Software
*Gurus* Derek Stone Posted April 6, 2003 *Gurus* Posted April 6, 2003 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. Quote Posting Guidelines
*Gurus* Derek Stone Posted April 6, 2003 *Gurus* Posted April 6, 2003 I am always on-line, but once in a while it hangs for 30 seconds trying to establish an internet connection. Why would it be trying to establish a connection if you're already online? I'm guessing you are as clueless as I am. Quote Posting Guidelines
Moderators Robby Posted April 6, 2003 Author Moderators Posted April 6, 2003 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. Quote Visit...Bassic Software
Moderators Robby Posted April 6, 2003 Author Moderators Posted April 6, 2003 Hmm, When I disable my fire-wall it works great, so I changed the version number in the AssemblyInfo to a fixed value and all is well. Thanks. Quote Visit...Bassic Software
*Gurus* Derek Stone Posted April 6, 2003 *Gurus* Posted April 6, 2003 I had a feeling it was due to an external problem. Glad you found it. Quote Posting Guidelines
Moderators Robby Posted April 7, 2003 Author Moderators Posted April 7, 2003 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. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.