1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Stop a loop with a button?

Discussion in 'Questions (Windows Mobile)' started by N1c0_ds, Feb 5, 2009.

  1. N1c0_ds

    N1c0_ds Active Member Licensed User

    I am trying to insert a "cancel" button to stop a download while it's in the download loop (using the downloadfile method with the HTTP lib) but the UI is frozen until a download is completed.

    Any idea of how I could do this?
     
  2. Cableguy

    Cableguy Expert Licensed User

    yes, use the new asyncronous method, wich runs in its own thread inside the dll...
    That way you can still interact with the forms controls...
    To stop th download just set the response to an emty string...
     
  3. N1c0_ds

    N1c0_ds Active Member Licensed User

    Alright, I'll try that.

    Now how can you check for a connection's validity with the asynchronous method? I already use it to silently download screenshots but I don't know how to check for an error.

    I currently use "NoConnection", a subs that returns "false" if an error occurs while getting the response, but I don't know how to implement this on an async. call.
     
  4. Cableguy

    Cableguy Expert Licensed User

    from the lattest http dll help file:

     
  5. N1c0_ds

    N1c0_ds Active Member Licensed User

    Here's the code I use now to save .cab files. How can I stop it with a cancel button? (let's say floadingcancel, a softkey button)

    Code:
    #Region SaveCab
    Sub SaveCab(URL,InstallAfterDownload)
    Install=InstallAfterDownload

       
    If Prefs.AskForSaveLocation=True Then
          
    If SaveDialog.Show<>cCancel Then
             FilePath=SaveDialog.File
          
    Else
             
    Return
          
    End If
       
    Else
          
    If DirExist(AppPath & "\temp")=False Then DirCreate(AppPath & "\temp")
          FilePath=AppPath & 
    "\temp\application.cab"
       
    End If
       
       WaitCursor(
    True)
       
          
    If Checkconnection(URL)=False Then
             NoConnection(
    True,False)
             WaitCursor(
    False)
             
    Return
          
    End If
          
       Response.New1
       Request.New1(URL)
       Request.UserAgent=
    "Gecko/Beta (http://getgecko.org)"
       Request.GetAsyncResponse
    End Sub

    Sub Request_Response
       
    If Request.ResponseCode=200 Then
          Response.Value=Request.AsyncResponse 
    'Launch the request and get the response.
          Response.GetAsyncStream(Filepath) 'Get the stream
       Else
          WaitCursor(
    False)
          NoConnection(
    True,False)
       
    End If
    End Sub

    Sub Response_Stream
    WaitCursor(
    False)
    Retry:
       
    If Install=True Then
          ShellAndWait(
    "wceload.exe"Chr(34) & Filepath & Chr(34))
          
    If Msgbox("Did the application install successfully?","Installation",cMsgboxYesNo,cMsgboxQuestion)=cNo Then Goto Retry
       
    End If
    FrmLoading.Close
    End Sub
    #End Region
     
  6. joel2009

    joel2009 Member Licensed User

    i'm not as farmiliar with the http library, but you could add an if value to check if a check box is checkd or not, and exit if it is. then set the buttons to change the value of the check box too true (and of course reseeet it to false on download button click)
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Something like:
    Code:
    Sub btnStop_Click
     Response.CancelStream = 
    true
    End Sub
    This button should be disabled by default, and only enabled after the call to GetAsyncStream.
    You could also use Request.DownloadedBytes to show the progress to the user.
     
  8. N1c0_ds

    N1c0_ds Active Member Licensed User

    Both things work perfectly! Thanks a lot!

    I use a timer's tick event to refresh the loading bar. The progressbar's value is Response.Downloadedbytes and its maximum is Response.Contentlenght.

    :sign0162:
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice