Hello. I spent couple days reading threads in vb.net but still I am so confused and none of examples work. Would you please help me get the example below to work in a thread - it download the file from internet but showing download progress. Obviously it does not work in thread so I dont see progressbar being refreshed at all.Any help greatly appreciated.Code:Private Function DownloadChunks(ByVal sURL As String, ByVal pProgress As ProgressBar, ByVal Filename As String) 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 Try URLReq = WebRequest.Create(sURL) URLRes = URLReq.GetResponse Dim sChunks As Stream = URLReq.GetResponse.GetResponseStream pProgress.Maximum = URLRes.ContentLength Do iBytesRead = sChunks.Read(bBuffer, 0, 1000) FileStreamer.Write(bBuffer, 0, iBytesRead) If pProgress.Value + iBytesRead <= pProgress.Maximum Then pProgress.Value += iBytesRead Else pProgress.Value = pProgress.Maximum End If Thread.Sleep(100) Loop Until iBytesRead = 0 pProgress.Value = pProgress.Maximum sChunks.Close() FileStreamer.Close() Return True Catch ex As Exception Return False End Try End Function
Thank you.


LinkBack URL
About LinkBacks




Reply With Quote


Bookmarks