GetAsyncStream
Previous Top Next

Asynchronously downloads the complete stream and saves it to a file.
The Stream event will be raised after downloading the complete stream.
This method will not block like GetStream.
It is possible to cancel the download by setting CancelStream to false.
DownloadedBytes holds the number of files that were already downloaded.

Syntax: GetAsyncStream (File As String)
File - The full path of the file that the stream will be saved to.
Note that this file will first be deleted.

Example:
Sub Globals
      total = 0
      URL = "http://www.basic4ppc.com/images/modules.jpg"
End Sub

Sub App_Start
      Form1.Show
      request.New1(URL)
      response.New1
      request.GetAsyncResponse
End Sub

Sub request_Response
      If request.ResponseCode = 200 Then '200 is the code of successful connections.
            response.Value = request.AsyncResponse
            total = Round(Response.ContentLength/1000)
            response.GetAsyncStream(AppPath & "\tempImage.jpg")
            timer1.Enabled = True
            btnCancel.Enabled = True
      Else
            Msgbox("Error getting response: " & request.ErrorMessage & CRLF _
            & "Response code: " & request.ResponseCode)
      End If
End Sub

Sub response_Stream
      Msgbox("Finished downloading file.")
      timer1.Enabled = False
End Sub

Sub Timer1_Tick
      label1.Text = "Download " & Round(response.DownloadedBytes / 1000) &" kb out of " & total & " kb"
End Sub