Delphi-如何实现自定义超时

时间:2019-05-14 13:41:25

标签: delphi timeout comobject idispatch

我想为包装类实现自定义超时。

此代码有效,但没有超时:/

让我看看实现了什么

定义:

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

实施:

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;

使用过:

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;

我正在使用Tokyo 10.2,并且想在“ TComplusWrapper.Execute”函数中编写自定义超时,以监控和例如如果花费太长时间,则强制结束“ fComplus.fxExecute()”函数。 有什么想法吗?

预先感谢

0 个答案:

没有答案