Imports System.IO
Imports System.Net
Private Sub Download(ByVal sUrl As String, ByVal sFilePath As String)
'Initialize Download
_oWebClient = New WebClient
_oStream = _oWebClient.OpenRead(sUrl)
_oFile = New FileStream(sFilePath, FileMode.Create)
_oStream.BeginRead(_DataBuffer, 0, 8192, AddressOf AsynDownload, Nothing)
End Sub
Private Sub AsynDownload(ByVal ar As IAsyncResult)
Dim intCount As Integer
Try
intCount = _oStream.EndRead(ar)
If intCount < 1 Then
_oStream.Close()
_oFile.Close()
_oWebClient.Dispose()
'MsgBox("Done")
ProgressBar1.Value = 0
ContinueInstall()
Exit Sub
End If
_iTotalBytes += intCount
_oFile.Write(_DataBuffer, 0, intCount)
Dim params() As Object = {_iTotalBytes}
Me.Invoke(New BarInvoker(AddressOf Me.DisplayBar), params)
_oStream.BeginRead(_DataBuffer, 0, 8192, AddressOf AsynDownload, Nothing)
Catch e As Exception
MsgBox(e.Message)
End Try
End Sub
Private Sub DisplayBar(ByVal byteCount As Integer)
If ProgressBar1.Maximum > byteCount \ 1024 Then
ProgressBar1.Value = byteCount \ 1024
End If
End Sub