相关疑难解决方法(0)

实现线程Terminate方法的覆盖

我试图覆盖虚拟TThread :: Terminate方法,但我发现只有设置Terminated标志才会调用我的覆盖.实现这个的正确方法是什么?

TTestThrd = class(TThread)
private
    { Private declarations }

protected
    { Protected declarations }
    procedure Execute(); override;
    procedure DoTerminate(); override;

public
    { Public declarations }
end;


procedure TTestThrd.Execute();
var
    bTerminated: Boolean;
begin
    // This is the main thread loop
    try
        while (not Terminated) do
            begin
            // Sleep or use TEvent::Waitfor...
            end;
    finally
        // Terminated (or exception) so free all resources...
        bTerminated := True;        // Why is this called...
    end;
end;

procedure TTestThrd.DoTerminate();
var
    bDoTerminateCalled: …
Run Code Online (Sandbox Code Playgroud)

delphi multithreading

-1
推荐指数
1
解决办法
735
查看次数

标签 统计

delphi ×1

multithreading ×1