can you interrupt an Indy connect call?
I have a connect that I give 20 seconds to for a timeout (slow link). I need to allow my user to cancel this connect call.
I already have the connect occurring in a thread so that I can keep the GUI going, but how do I tell Indy to cancel? I also have to call cancel from the main thread because the connect call is开发者_运维技巧 blocked. Is this possible?
This is for C++ Builder, but a Delphi answer will do just fine.
The only way to abort Connect() is to call Disconnect() from a different thread context than the one that is calling Connect(). In this situation, your main thread can call Disconnect() directly, and then your thread can handle the exception that Connect() raises in reply.
Perhaps another way is to create your own TIdAntiFreeze descendant, and in it's Process() method throw an error if the client wants to quit which would abort the connection attempt and then you can trap for this particular error and respond accordingly.
Once you create a TIdAntiFreeze component, the connection routines should find it. You can fine tune it a little with the IdleTimeout property which is how often the DoProcess() method is called.
Alternately, create an IOHandler of your own which uses a TIdConnectThread like this AntiFreeze code does and handle the error more gracefully.
精彩评论