Mayam A.
Mayam A.

Reputation: 31

How to trigger TIdHTTP.Disconnect when running in a OmniThreadLibrary task

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.

Upvotes: 3

Views: 329

Answers (0)

Related Questions