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:
01300844
Views:
20
From my newbie point of view it sounds like the client should be declared with the public access. Otherwise which client you're trying to stop - a new instance?

>That would be nice, but the client is scoped to the local procedure.
>
>Glenn
>
>>>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
Reply
Map
View

Click here to load this message in the networking platform