Public Sub downloadFile(ByVal url As String)
LogFile.displayMessage("add url=" & url)
downloadURLs.Enqueue(url)
If t Is Nothing Then
LogFile.displayMessage("create new thread")
t = New Thread(AddressOf ThreadedDownloadFile)
End If
If Not t.IsAlive Then
LogFile.displayMessage("start thread")
t.Start()
End If
End Sub
Private Sub download()
LogFile.displayMessage("thread running count=" & downloadURLs.Count)
If downloadURLs.Count > 0 Then
Dim client = New WebClient()
AddHandler client.DownloadFileCompleted, AddressOf downloadFileCompleted
AddHandler client.DownloadProgressChanged, AddressOf downloadProgressChanged
Dim url = downloadURLs.Dequeue()
LogFile.displayMessage("downloading url=" & url)
url = WebRequest.Create(url).GetResponse.ResponseUri.AbsoluteUri
Dim fileName = url.Substring(url.LastIndexOf("/") + 1)
progress = 0
LogFile.displayMessage("downloading NOW NOW NOW url=" & url)
client.DownloadFile(New Uri(url), localAddress & fileName)
End If
LogFile.displayMessage("thread end")
End Sub
Private Sub downloadFileCompleted() 'ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
LogFile.displayMessage("download complete ") ' & e.Result)
LogFile.displayMessage("set next download going")
download()
End Sub
but on the second round it gets the url and then stops at the downloadfile.
it does this with downloadfileasync also.
i have seen many webpages discussing this, but none that fix it
does anyone know how this can be fixed?
ADDITIONAL details
i do start a new thread, but no matter how i do it, the webclient.downloadfile or downloadfileasync etc.
they all seem to work great the first time but then on second call, they do seem to download as a file appears, but the progress call is never made, and it never returns to complete.
I have tried dispose, then nothing it, then redeclare it, and even force garbage collect after dispose, nothing.
but it still does not want to work.
I am exploring doing the transfer myself, via streams
The problem was nothing to do with the download, it was this code:-
Dim wrequest = WebRequest.Create(url)
Dim wresponce = wrequest.GetResponse()
I now call close and null the instances after there use.
'making sure to close off unneeded resources after use
wresponce.Close()
wresponce = Nothing
wrequest = Nothing