Hey guys, i'm working on a program, kind of like a download manager.
I have a background worker set up that handles the download, and it works great the first time, but the second time it just sits and times out.
Function DL(ByVal sURL As String, ByVal pProgress As ProgressBar, ByVal Filename As String)
'GroupBox1.Show()
Dim URLReq As HttpWebRequest
Dim URLRes As HttpWebResponse
Dim FileStreamer As New FileStream(Filename, FileMode.Create)
Dim bBuffer(999) As Byte
Dim iBytesRead As Integer
BackgroundWorker1.ReportProgress(0)
Dim rplcr As Integer = 0
Try
URLReq = WebRequest.Create(sURL)
URLRes = URLReq.GetResponse
Dim sChunks As Stream = URLReq.GetResponse.GetResponseStream
'pProgress.Maximum = URLRes.ContentLength
' BackgroundWorker1.ReportProgress(0)
Do
iBytesRead = sChunks.Read(bBuffer, 0, 1000)
FileStreamer.Write(bBuffer, 0, iBytesRead)
If rplcr + iBytesRead <= pProgress.Maximum Then
rplcr += iBytesRead
BackgroundWorker1.ReportProgress(rplcr)
Else
rplcr = pProgress.Maximum
BackgroundWorker1.ReportProgress(rplcr)
MsgBox("Download Complete")
BackgroundWorker1.ReportProgress(0)
End If
Loop Until iBytesRead = 0
rplcr = pProgress.Maximum
BackgroundWorker1.ReportProgress(rplcr)
sChunks.Close()
sChunks.Dispose()
URLRes.Close()
FileStreamer.Close()
UnZip(Filename)
If IO.File.Exists(Filename) Then
IO.File.Delete(Filename)
End If
MsgBox("Download Complete")
BackgroundWorker1.ReportProgress(0)
Return True
Catch
MsgBox(Err.Description)
Return False
End Try
End Function
I managed to narrow the problem down to the httpwebresponse URLres, how can i renew this and use it multiple times?
Thanks,
-Z