File Downloader hangs

Martin F 1 Reputation point

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
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)
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.
30,203 questions
{count} votes