File Downloader hangs

Martin F 1 Reputation point
2022-02-15T13:17:57.503+00:00

Hello all
With the following code you can download files and pause and resume the download.
The code works fine on a slow network connection.
But if you have a gigabit network the application hangs. This means that the server with the file to be downloaded is on the same network.
What are the possible solutions?
Thanks for your answers.
Greetings Martin

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports AltoHttp

Public Class Form1
Private httpDownloader As HttpDownloader

Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
Dim DownloadFolder As String
DownloadFolder = "c:\temp\" & "Download\"
httpDownloader = New HttpDownloader(txtUrl.Text, $"{DownloadFolder}\{System.IO.Path.GetFileName(txtUrl.Text)}")
AddHandler httpDownloader.DownloadCompleted, AddressOf HttpDownloader_DownloadCompleted
AddHandler httpDownloader.ProgressChanged, AddressOf HttpDownloader_ProgressChanged
httpDownloader.Start()
End Sub

Private Sub HttpDownloader_ProgressChanged(ByVal sender As Object, ByVal e As AltoHttp.ProgressChangedEventArgs)
progressBar.Value = CInt(e.Progress)
lblPercent.Text = $"{e.Progress.ToString("0.00")} % "
lblSpeed.Text = String.Format("{0} MB/s", (e.SpeedInBytes / 1024.0R / 1024.0R).ToString("0.00"))
lblDownloaded.Text = String.Format("{0} MB", (httpDownloader.TotalBytesReceived / 1024.0R / 1024.0R).ToString("0.00"))
lblStatus.Text = "Downloading..."
End Sub

Private Sub HttpDownloader_DownloadCompleted(ByVal sender As Object, ByVal e As EventArgs)
Me.Invoke(CType(Function()
lblStatus.Text = "Finished"
lblPercent.Text = "100%"
Return 0
End Function, MethodInvoker))
End Sub

Private Sub btnPause_Click(sender As Object, e As EventArgs) Handles btnPause.Click
If httpDownloader IsNot Nothing Then httpDownloader.Pause()
End Sub

Private Sub btnResume_Click(sender As Object, e As EventArgs) Handles btnResume.Click
If httpDownloader IsNot Nothing Then httpDownloader.Resume
End Sub

End Class

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
38,569 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.