3

I am wondering how I may Disconnect an instance of TIdHTTP in Delphi Seattle while it is executed in an anonymous procedure of CreateTask from the OmniThreadLibrary.

My current code looks like this:

task := CreateTask(
procedure(const task: IOmniTask)
var
  http: TIdHTTP;
begin

  http := TIdHTTP.Create;

  try
    http.Get('http://192.168.1.14/stats.php?recalc');
  finally
    http.Free;
  end;

end).Run;

The request takes sometimes very long (like 40-60 seconds) and the user should have the opportunity to abort the request.

I am aware of using TIdHTTP's OnWork event, but in my case this is not suitable. OnWork gets called when there is a read/write operation, but while waiting for the server that is not the case.

Mayam A.
  • 31
  • 3
  • 1
    The question is basically: How to cancel Indy GET from a different thread ... and is answered here: http://stackoverflow.com/questions/6922787/how-stop-cancel-a-download-using-tidhttp – gabr Jun 14 '16 at 20:36
  • 1
    @gabr thanks for your comment. I am aware of this answer, but in for my case this is not suitable. OnWork gets called when there is a read/write operation, but while waiting for the server that is not the case. – Mayam A. Jun 15 '16 at 07:45
  • Then you should edit the question and make that obvious, please. I have reopened it so you can do that. – gabr Jun 15 '16 at 07:58

0 Answers0