我试图覆盖虚拟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)