On Feb 23, 2006, at 2:04 PM, jda wrote:

I want to download a file with an HTTPSocket. While it's downloading I put up a dialog with a progress bar. When the download is finished the dialog is dismissed.

To do this, I have created a thread that issues a .get command via an HTTPSocket. The socket has a "done" property that it sets with DownloadComplete fires. The thread waits for this (or an error, or usercancelled), and then exits. Here's the basic code:

    mySocket.get theURLToDownload, f
while DownloadDone = false and DownloadError = 0 and UserCancelled = false
    wend

The problem is that while the while/wend loop runs, the socket doesn't receive any data (ReceiveProgress never fires). The socket should run asynchronously (and in any case, is called from a thread), but no data are received.

What am I doing wrong? I imagine there is a simply solution to this problem that is eluding me because of a misunderstanding on my part.

Use the HTTPSocket events to your advantage. You are trying to force a "Yield = False" while still taking advantage of the events. I don't know why the HTTPSocket events are not firing unless the "While...Wend" structure does not yield to BackgroundTasks like the "For...Loop".

But you really don't need to use threads in this case since all Socket classes seem to have their own hidden thread mechanism (so that the socket can continue to operate even with other tasks going on). So try using this very simple example:

Create a new modal-frame Window called "DownloadProgress" with a ProgressBar, a Cancel button (PushButton), and a HTTPSocket.

In the HTTPSocket.ReceiveProgress() event:

    ProgressBar1.Maximum = TotalBytes
    ProgressBar1.Value = BytesReceived

In the HTTPSocket.DownloadComplete()

    Self.Close

In the CancelBtn.Action():

    HTTPSocket1.Disconnect
    Self.Close

Finally, add a method:

  Sub Get(url, f As FolderItem)
    HTTPSocket1.Get(url, f)
  End Sub

Then all you need to do to download a file and display the window is to call:

    DownloadProgress.Get(myUrl, myFolderItem)

You can make this more complex and more feature complete if you want (such as KB/s) but that is the basics. You might want to add some sort of notification in the case of an error, but this will get you started.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to