Stop an active TIdHTTP.Get ?

Hi,

I'm using the indy TIdHTTP component to download files via an asp page.  It works great, updating progress bars and time elapsed/remaining etc..

The only problem I have is that I cannot figure out how to stop an active download.  As per most operations that involve waiting, there's a cancel button, but I can't make it work!

I've tried using disconnect, disconnectSocket and even freeing and recreating the object, but these all cause either an access violation or an annoying dialog that says the connection was closed gracefully, but then makes the app hang.

Can anyone advise me on this?

Thanks a lot,

John.
LVL 6
JaymolAsked:
Who is Participating?
 
Lee_NoverConnect With a Mentor Commented:
raise an EAbort in the idhttp component's OnWork event

in the cancel button you'd do smtn like:
FCanceled:=true;

OnWork event:
if FCanceled then
begin
  FCanceled:=false;
  Abort;
end;


to use one thread and still have app responsivnes you can add Application.ProcessMessage in the OnWork event or put a TIdAntiFreeze on a form
0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

Try to use Threads
then you can stop or terminate the thread
also when you using threads your application will not be blocked while downloading (due to the blocking mode that indy use)

Regards,
0
 
JaymolAuthor Commented:
Yeah, thanks.  I've thought of that and am trying to avoid it due to laziness : )

Hopefully, there'll be a simpler solution, but if not, I guess I'll be threading stuff tonight!

Cheers,

John.
0
 
JaymolAuthor Commented:
Thanks Lee.

I have already made a thread for downloading and am going to do the same for the upload procedure, but would rather not have to rely on destroying the thread in order to destroy the objects within it.  I'll give your suggestion a go and let you know how I get on.

Thanks,

John.
0
 
Lee_NoverCommented:
I use a combination of both
it's the correct, clean and elegant way :)
0
All Courses

From novice to tech pro — start learning today.