webclient DownloadStringAsync freeze UI

coolcurrent4u

Newcomer
Joined
Apr 30, 2011
Messages
3
i have this code, with only one url at first, which seems to freeze the UI for about a minutes.

i wanted to get the web page html faster asynchronously, but this is not working for me

Is the httpwebrequest faster?

Code:
Private Sub Test(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
		Dim newstring As String = e.Result.ToString
		listBox1.Items.Add ("Finished" & e.UserState.ToString)
	End Sub
	
	Sub Button1Click(sender As Object, e As EventArgs)
		for each item as String in textbox1.Lines
			Dim SiteURI As New Uri(item)
			Dim wc As New WebClient
			wc.DownloadStringAsync(SiteURI)
			AddHandler wc.DownloadStringCompleted, AddressOf Test
		next
	End Sub
 
When you say it isn't working what exactly happens? Is it failing in any way or just not getting the results?

Using HttpWebRequest might be slightly faster but probably not significantly so in comparison - the biggest factor is probably going to be the bandwidth between the server and client more than anything.
 
It shouldn't freeze the GUI using the Async call, I just tried it on my PC here and I did notice the line
Code:
listBox1.Items.Add ("Finished" & e.UserState.ToString)
was throwing a null reference exception due to UserState being null, but once I removed that part it ran just fine with no hanging of the UI in the slightest.
 
Back
Top