WebClient.DownloadStringAsync

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Hi,
I want to download a string from a page in my site, so I use this and it works:
Visual Basic:
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 doesn't work:
Visual Basic:
                Dim SiteURI As New Uri("http://www.domain.com/setup.txt")
                NewString = WebClient.DownloadStringAsync(SiteURI)
Please help me :(
 

PlausiblyDamp

Administrator
Joined
Sep 4, 2002
Location
Lancashire, UK
Chuck this into a blank form and you should get the general idea
Visual Basic:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim SiteURI As New Uri("http://www.xtremedotnettalk.com/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
 
Top Bottom