Multithreaded web downloader (VBMultiThreadedWebDownloader)

The code sample demonstrates downloading files from web using multi-threads

VB.NET (69.5 KB)
10,354 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Slow thread downloads
    1 Posts | Last post November 14, 2017
    • It seems that there will always be 1 or 2 threads that downloads super slow.
      For example, in a scenario where 4 threads are used to download a ~200MB file, 3 threads would download at full speed and finish the 75%. But this one thread downloads super slow(~100-200KB/s compares to ~3MB/s with the other 3). which slows down the whole downloading process. 
      Also tested with 8 threads and 6 threads, same thing happens all over again.
      Does anyone know why this would happen? Any help or idea is greatly appreciated.
  • The EXE does not work out of the box
    4 Posts | Last post October 07, 2016
    • When I built the exe in VS 2010, it built successfully. But then I tried to download a file, it gave an exception. Does any one know how to fix this ?
    • I found the exception and fixed it. It was division by zero, overflow exception. It works well now.
       Private Sub InternalDownloadProgressChanged(ByVal cachedSize As Integer)
              Dim speed As Integer = 0
              Dim current As Date = Date.Now
              Dim interval As TimeSpan = current.Subtract(_lastNotificationTime)
                  If interval.TotalSeconds < 60 AndAlso interval.TotalSeconds > 0 Then
                      speed = CInt(Fix(Math.Floor((Me.DownloadedSize + cachedSize - Me._lastNotificationDownloadedSize) / interval.TotalSeconds)))
                  End If
              Catch ex As Exception
                  'Debug.Print("Looking for Overflow exception @Pos3= " & ex.ToString)
              End Try
              _lastNotificationTime = current
              _lastNotificationDownloadedSize = Me.DownloadedSize + cachedSize
              Me.OnDownloadProgressChanged(New DownloadProgressChangedEventArgs(Me.DownloadedSize + cachedSize, Me.TotalSize, speed))
          End Sub
    • Further more, this cant be used for files larger than 2.1 gb, as its a limitation of the long data type.
    • Thank you so much. I also see this error but not always find the cause.