views:

110

answers:

1

Hi everybody, I am having the worst trouble getting around a bug, and am hoping that I can get some advice on this site. In short, I am trying to make an asynchronous web service call from my VB.NET application. But my "client_DownloadDataCompleted" callback is NEVER being called when the download is complete.

Here is my complete code:

Public Sub BeginAsyncDownload(ByVal Url As String)

    Dim waiter As System.Threading.AutoResetEvent = New System.Threading.AutoResetEvent(False)
    Dim client As WebClient = New WebClient()

    'client_DownloadDataCompleted method gets called when the download completes.
    AddHandler client.DownloadDataCompleted, AddressOf client_DownloadDataCompleted

    Dim uri As Uri = New Uri(Url)
    Downloading = True  'Class variable defined elsewhere
    client.DownloadDataAsync(uri, waiter)

End Sub

Private Sub client_DownloadDataCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
    MessageBox.Show("Download Completed")
    Downloading = False
    Debug.Print("Downloaded")
End Sub

Again, the client_DownloadDataCompleted method is never being called. I have also tried using the method:

Private Sub client_DownloadDataCompleted(ByVal sender As Object, ByVal e As DownloadDataCompletedEventArgs)

With no luck. What I really need is that "Downloading" variable to be switched off when the download is complete.

Thanks in advance! Brett

A: 

This is a tough one. I spent a little time on this and wasn't able to figure out why it wasn't getting called, sorry.

If you aren't able to get this to work, I have some code on CodePlex that includes a WebHelper class that might help you. I tried to make it as easy to use as WebClient but with all the power of HttpWebRequest.

The project is called BizArk. I wrote it just as a repository of code for myself. Feel free to just use the bits you want, I don't have any particular interest in how the code is used (as long as it's not used for evil :).

Brian