Page 1 of 2
Abort a downloadfile()
Posted: Mon Aug 07, 2023 6:30 pm
by papiosaur
Hello,
i would like to abort a
DownloadFile() command with a button with ID "abort" but don't find the solution with many tries.
My command line is :
Code: Select all
Downloadfile(entry$, {File = f$, Adapter = "hurl"}, p_SetProgress)
My function p_SetProgress is:
Code: Select all
Function p_SetProgress(msg)
maxi$ = msg.Total
moai.Set("prgbar", "max", maxi$)
moai.Set("prgbar", "level", msg.count)
EndFunction
I see in documentation to add a msg.action in the "func" tion but anything work...
Thanks for your help.
Re: Abort a downloadfile()
Posted: Tue Aug 08, 2023 10:26 pm
by airsoftsoftwair
By default
DownloadFile() runs synchronously so you can't abort it because it won't return before it's finished. If you want to be able to abort it, you need to set the "Async" tag to TRUE and then repeatedly call
ContinueAsyncOperation() until it returns TRUE, e.g. something like this:
Code: Select all
handle = DownloadFile("http://example.com/example.zip", {Async = True, File = "example.zip"})
Repeat
done = ContinueAsyncOperation(handle)
...do something...
VWait
Until done = True
In such a setup, you can then call
CancelAsyncOperation() to abort the download.
Re: Abort a downloadfile()
Posted: Tue Aug 08, 2023 10:33 pm
by papiosaur
Thanks a lot Andreas for your example and your help!
Re: Abort a downloadfile()
Posted: Wed Aug 09, 2023 1:28 pm
by papiosaur
@Andreas: i wrote this but download don't start...
Code: Select all
handle = DownloadFile(entry$, {Async = True, File = f$, Adaptater = hurl"}, p_SetProgress)
Repeat
done = ContinueAsyncOperation(handle)
VWait
Until done = True
I obtain a Hollywood request with:
File:script.hws (current line : 485 - In function: ContinueAsyncOperation)
An idea please?
Re: Abort a downloadfile()
Posted: Wed Aug 09, 2023 3:47 pm
by plouf
dont be so hurry when thiking
see, first there no adaptater (french?) , hurl has only closing ", 3rd argument in DownloadFile ...doe not exist
Code: Select all
handle = DownloadFile(entry$, {Async = True, File = f$, Adapter = "hurl"})
Repeat
done = ContinueAsyncOperation(handle)
VWait()
Until done = True
Re: Abort a downloadfile()
Posted: Wed Aug 09, 2023 3:57 pm
by papiosaur
@plouf: bad adaptation of french langage
Thanks! I correct that
Re: Abort a downloadfile()
Posted: Wed Aug 09, 2023 4:16 pm
by papiosaur
Bizarre, my
ContinueAsyncOperation() don't change color in my IDE (FlowStudio)
CancelAsyncOperation() too...
And it's not in french
I have always the same problem with correction...
Maybe not implemented in MorphOS version?
Re: Abort a downloadfile()
Posted: Sat Aug 12, 2023 6:49 pm
by papiosaur
I have retested and bizarely i have a new message error now immadiatly when i click on "Abort" button.
Requested object not found!
File: script.hws (current line: 459 - In function: ContinueAsyncOperation)
For my "Abort" button the action is : CancelAsyncOperation(handle)
Re: Abort a downloadfile()
Posted: Sun Aug 13, 2023 9:57 am
by plouf
You have to learn to create small snipets to actually track down problems
You are a smart guy, capable for a lot . But taking thinks too "fast and furius"
In order to understand your problem create a
MCVE. Thats the minimun possible code fully executable , that its fully self alone
Then think of the problem line by line, of what wrong happen
If not find paste the
MCVE here to check and get help from rest

Re: Abort a downloadfile()
Posted: Sun Aug 13, 2023 7:08 pm
by papiosaur
Thanks plouf for the smart guy

I hope a little
My big problem, it's very difficult for me to do a minimal code with just only the necessary...
In my project, there is databases, internet access, a listview, many buttons, etc...
I have found the problem i think, it work now.
Sometimes i have errors message and now it's ok, bizarre...
Async mode is more sensible to bug no?
I will post my code for
DownloadFile() and Abort command via button soon after more test and i will add comments.