Abort a downloadfile()

Discuss GUI programming with the RapaGUI plugin here
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Abort a downloadfile()

Post 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.
User avatar
airsoftsoftwair
Posts: 5450
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Abort a downloadfile()

Post 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.
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Abort a downloadfile()

Post by papiosaur »

Thanks a lot Andreas for your example and your help!
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Abort a downloadfile()

Post 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?
plouf
Posts: 473
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Abort a downloadfile()

Post 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
Christos
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Abort a downloadfile()

Post by papiosaur »

@plouf: bad adaptation of french langage ;-)

Thanks! I correct that
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Abort a downloadfile()

Post 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?
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Abort a downloadfile()

Post 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)
plouf
Posts: 473
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Abort a downloadfile()

Post 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 ;-)
Christos
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Abort a downloadfile()

Post 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.
Post Reply