Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
WebClient.DownloadFileAsync Cancel not working
Message
 
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01300799
Message ID:
01300825
Views:
17
>We have developed a WebForm to allow users to download updates from our website. So far the download process is going well. We do have a problem with WebClient.Cancel however. When issued we never receive an event at our handler (DownloadFileComplete) and to make matters worse the download continues until the file is completely processed.
>
>
>  Public Sub GetFile(ByVal fName As String, ByVal ftpPath As String, ByVal locPath As String)
>        Dim client As New WebClient
>        AddHandler client.DownloadFileCompleted, AddressOf DownloadFileComplete
>        '  Specify a progress notification handler.
>        AddHandler client.DownloadProgressChanged, AddressOf DownloadProgress
>        Try
>            client.Credentials = New NetworkCredential("upgrades", "jamboree8035")
>
>            client.DownloadFileAsync(UriPath, locPath)
>        Finally
>            'Response.Redirect("default.aspx")
>        End Try
>    End Sub
>
>   Public Sub DownloadFileComplete(ByVal sender As Object, ByVal e As DownloadDataCompletedEventArgs)
>        Response.Redirect("~/default.aspx")
>    End Sub
>
>    Sub DownloadProgress(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
>        Me.Label1.Text = e.ProgressPercentage.ToString
>    End Sub
>
>    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
>        Dim client As New WebClient
>        client.CancelAsync()
>        client.Dispose()
>    End Sub
>
>
>Any ideas?
>
>Thanks

I'm sorry if this is a wrong question, but why do you define dim client as new WebClient again in your btnCancel code? Should it use already defined client instead?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform