It’s the first time I work on a multi-threads application with Delphi so all is still fesh for me, but I read a lot.
My thread is simple, to be short I just use Indy (IdHTTP) to GET the content of a web page and then I verify if the content contains a string. No problems here.
Now, to terminate threads I use a boolean with WHILE DO. It seems working but here is the problem : like I use a Timeout with Indy, sometimes I must wait the end of the timeout period before threads finish (when the server is not responding for example)…
It’s annoying, especially when I use +200 threads. With other softwares using multi-threads and similar procedure, when I click “Stop” all is stopped in few seconds, and that is what I need.
I read that I should use an AntiFreeze, to allow IdHTTP to “read my instuctions”…
So, I’m a bit lost here.
I don’t think it’s very necessary, but here is my code : http://pastebin.com/G7De8bgb
Thanks in advance for lights 🙂
Beny
The class
TidHTTPhas anOnWorkevent. Use this event to cancel the data downloading or uploading. How to cancel with this event? Fire an Abort silent exception.This is a pseudo code:
Take into account that the stages on which OnWork are called are random. The event could be called at the middle of the request, at the begging or even at the end. The code above will work as if you press the stop button on the browser.
[UPDATE]
Forget to mention that if then OnWork event is not called when the Thread is hanged out for a reply of the server, the use can use a timeout if the “last response” was received a specified milliseconds ago. Use
GetTickCountfor this.