Код:

' Получить собственно файл
If PathForDownl = "" Then
FlName = IO.Path.GetTempPath & IO.Path.GetFileName(fl)
Else
PathForDownloads = GetMaxPath(PathForDownloads)
If IO.Directory.Exists(PathForDownloads) = False Then
IO.Directory.CreateDirectory(PathForDownloads)
End If
FlName = PathForDownloads & "\" & IO.Path.GetFileName(fl)
End If
If IO.Path.GetFileName(FlName).Split(IO.Path.GetInvalidFileNameChars).Length > 1 Then
FlName = IO.Path.GetTempPath & GetUIN() & ".tmp"
End If
'Открыть файл
' Поток в файл (объявление)
Dim fstr As New System.IO.FileStream(FlName, System.IO.FileMode.OpenOrCreate)
Dim dnl_size As Long = 0
'Открытие потока в файл
'fstr = System.IO.File.OpenWrite(FlName)
' Получить асинхронно
If WaitForDownload = False Then
fstr.Close()
thr = New Threading.Thread(AddressOf AsyncDownload)
thr.Start(myHttpWebResponse.GetResponseStream)
' Получить синхронно
Else
FileDownloading = True
Dim myStreamReader As New IO.BinaryReader(myHttpWebResponse.GetResponseStream)
Dim all As New System.Collections.Generic.List(Of Byte)
Do
' Собственно получения порции данных
Dim bts() As Byte = myStreamReader.ReadBytes(BufferSize)
If bts.Length = 0 Then Exit Do
fstr.Seek(0, System.IO.SeekOrigin.End)
For Each bytevalue As Byte In bts
fstr.WriteByte(bytevalue)
fstr.Seek(0, System.IO.SeekOrigin.End)
dnl_size = dnl_size + 1
Next
'all.AddRange(bts)
' Вызов события Идет прием данных
ReceiveProgressInvoke(dnl_size)
Loop
'DownloadSuccess(all)
End If
' Функция реализующая поток, который скачивайт файл порциями BufferSize
Sub AsyncDownload(ByVal stream As Object)
FileDownloading = True
Dim myStreamReader As New IO.BinaryReader(stream)
Dim all As New System.Collections.Generic.List(Of Byte)
Dim fstr As New System.IO.FileStream(FlName, System.IO.FileMode.OpenOrCreate)
Dim dnl_size As Long = 0
Do
' Всякие Прерывания и Паузы потока
If FileDownloading = False Then DownloadCancelledInvoke() : myStreamReader.Close() : Exit Sub
While DownloadPause
System.Windows.Forms.Application.DoEvents()
If FileDownloading = False Then DownloadCancelledInvoke() : myStreamReader.Close() : Exit Sub
End While
' Собственно получения порции данных
Dim bts() As Byte = myStreamReader.ReadBytes(BufferSize)
If bts.Length = 0 Then Exit Do
fstr.Seek(0, System.IO.SeekOrigin.End)
For Each bytevalue As Byte In bts
fstr.WriteByte(bytevalue)
fstr.Seek(0, System.IO.SeekOrigin.End)
dnl_size = dnl_size + 1
Next
'all.AddRange(bts)
' Вызов события Идет прием данных
ReceiveProgressInvoke(dnl_size)
Loop
'DownloadSuccess(all)
End Sub