WebClient.DownloadStringAsync

ADO DOT NET

Well-known member
Joined
Dec 20, 2006
Messages
156
Hi,
I want to download a string from a page in my site, so I use this and it works:
Code:
NewString = WebClient.DownloadString("http://www.domain.com/setup.txt")
Just 1 problem that if there is a connection timeout, my application hangs out.
So should I use WebClient.DownloadStringAsync?
If so how?
I wrote this code but it doesnt work:
Code:
                Dim SiteURI As New Uri("http://www.domain.com/setup.txt")
                NewString = WebClient.DownloadStringAsync(SiteURI)
Please help me :(
 
Chuck this into a blank form and you should get the general idea
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim SiteURI As New Uri("http://www.computerhelp.forum/showthread.php?p=465032#post465032")
    Dim wc As New WebClient
    wc.DownloadStringAsync(SiteURI)
    AddHandler wc.DownloadStringCompleted, AddressOf Test

End Sub

Private Sub Test(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
    Dim newstring As String = e.Result
End Sub
 
Back
Top