Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

 

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

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Administrators
Posted

It shouldn't freeze the GUI using the Async call, I just tried it on my PC here and I did notice the line

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

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...