[RESOLVED] How to stop download once started it-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] How to stop download once started it

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    Resolved [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

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,238

    Re: How to stop download once started it

    Which method do you use to download the file?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    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

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,238

    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?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    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

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,238

    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?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    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.
    Last edited by Netmaster; Feb 5th, 2011 at 02:48 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.