[RESOLVED] How to stop download once started it
Hi,
I created a form which,through the input of a URL via a textbox, downloads a file from the internet. For example I write in the textbox
http://www.downloadfile.com/filetobedownloaded.rar
and after I hit the download button the software starts downloading the file (the progress is shown via a progress bar).
What about if I want to stop the download before the download is over?
How can I do it? What should I write in the "Stop" button?
Thank you in advance,
Andrea
Re: How to stop download once started it
Which method do you use to download the file?
Re: How to stop download once started it
Private WithEvents _Downloader As WebFileDownloader
Try
_Downloader = New WebFileDownloader
_Downloader.DownloadFileWithProgress("URL" & ComboBox1.Text & ".rar", txtDownloadTo.Text.TrimEnd("\"c) & GetFileNameFromURL("URL" & ComboBox1.Text & ".rar"))
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
Re: How to stop download once started it
Since the WebFileDownloader class is a custom type, you will have to tell us what's in it. Do you have the code for that class?
Re: How to stop download once started it
Yes! here it is (I really thank you for your help):
Public Class WebFileDownloader
Public Event AmountDownloadedChanged(ByVal iNewProgress As Long)
Public Event FileDownloadSizeObtained(ByVal iFileSize As Long)
Public Event FileDownloadComplete()
Public Event FileDownloadFailed(ByVal ex As Exception)
Private mCurrentFile As String = String.Empty
Re: How to stop download once started it
Just listing the class member names won't help. Is it too much to post the full class?
Re: How to stop download once started it
I resolved by writing the program back again in a different way!
This time I used .DownloadFileAsync for downloading and .CancelAsync() for stopping the download.