Stopping Delphi Indy threads without having to wait end Timeout

后端 未结 2 607
礼貌的吻别
礼貌的吻别 2021-01-01 04:48

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 Ind

2条回答
  •  时光说笑
    2021-01-01 05:34

    I've had a similar issue using Indy and webservices where the system we were talking too were unreliable at best ( I had to set read timeouts of 30 mins for some calls).

    Since the Rio Calls ( and your IdHTTP ) calls are blocking your cannot canel/abort them directly.

    You can however (if using different threads) disconnect the underlying socket which will cause an exception in the get/webcall.

    I've done a quick hack to test the idea using just TIdHTTP and it appears to work as it does with the Rio.

    In your main/controlling thread you need to call the IDHTTP.Disconnect, then catch the exception that will be raised in you thread. From looking at your code you are creating the IdHTTP in the Thread.Execute, you will have to move the declaration of that to the class's constructor to allow an Abort function on your thread class to simple disconnect the socket.

    I've used Delph 7 and INDY10 just incase thats differnet to your setup.

    Hope that helps

    BTW

    If anyone knows of a better/less agresive method I'd love to see that too.

提交回复
热议问题