【发布时间】:2010-03-03 23:39:08
【问题描述】:
我在解决一个错误时遇到了最大的麻烦,我希望我能在这个网站上得到一些建议。简而言之,我正在尝试从我的 VB.NET 应用程序进行异步 Web 服务调用。但是当下载完成时,我的“client_DownloadDataCompleted”回调永远不会被调用。
这是我的完整代码:
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
同样,client_DownloadDataCompleted 方法永远不会被调用。我也试过用这个方法:
Private Sub client_DownloadDataCompleted(ByVal sender As Object, ByVal e As DownloadDataCompletedEventArgs)
没有运气。我真正需要的是在下载完成后关闭“下载”变量。
提前致谢! 布雷特
【问题讨论】:
标签: vb.net asynchronous webclient