0

I want to implement a custom timeout for my wrapper class.

This code is working but without timeout :/

Let see what I've implemented:

Definition:

TComplusWrapper = class(TObject)
private
    fComplus: OleVariant;
public
    constructor Create;
    destructor Destroy; override;
    function Execute(paramOne: String; paramTwo: string): String;
end;

Implementation:

constructor TComplusWrapper.Create;
var
    fMAchineName,
    fApplication: string;
begin
    fMAchineName := 'mydomain.com';
    fApplication := '{83EAA392-6154-419B-9177-E0BB4C3F8785}';
    fComplus := CreateRemoteComObject(FMachineName, StringToGUID(FApplication)) as IDispatch;
end;

destructor TComplusWrapper.Destroy;
begin
    fComplus := VarNull;
end;

function TComplusWrapper.Execute(paramOne: string; paramTwo: string): string;
begin
    //here I want to implement the timeout
    Result := fComplus.fxExecute(paramOne, paramTwo);
end;

Used:

procedure TMain.btnFakeClick(Sender: TObject);
var
    complus: TComplusWrapper;
    cXML,
    fComputerName: string;
begin
    cXML := '<exp>myXml</exp>';

    fComputerName := 'LT-134242';

    complus := TComplusWrapper.Create;
    try
        showMessage(complus.Execute( cXML, FComputerName))
    finally
        complus.Destroy;
    end;
end;

I'm using Tokyo 10.2 and want to write a custom timeout in the 'TComplusWrapper.Execute' function to monitor and e.g. forcefully end the 'fComplus.fxExecute()' function if it takes too long. Any possible idea?

Thanks in advance

Exe
  • 1
  • 1
  • It is unclear to me what you mean with "timeout". Do you want it to monitor and e.g. forcefully end the `fComplus.fxExecute()` method if it takes too long. Or do you want to delay the `fComplus.fxExecute() ` command? – Tom Brunberg May 14 '19 at 15:00
  • @TomBrunberg Thanks for the clarification. Exactly! I want it to monitor and e.g. forcefully end the fComplus.fxExecute() method if it takes too long. – Exe May 14 '19 at 15:16
  • 2
    You can't forcibly end a thread in a reliable way. Whatever your problem is, this isn't the solution. – David Heffernan May 14 '19 at 16:57
  • @DavidHeffernan thanks David – Exe May 15 '19 at 12:47

0 Answers0