等待一个线程结束的标准处理方法:
type
TMyThread = class(TThread)
private
FCount: Integer;
procedure UpdateInfo();
protected
procedure Execute;
override;
end;
{ TMyThread }
procedure TMyThread.Execute;
begin
FCount := 0;
while FCount < 1000do
begin
Inc(FCount);
Synchronize(UpdateInfo);
end;
end;
procedure TMyThread.UpdateInfo();
begin
Form1.Caption := IntToStr(FCount);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
test: TMyThread;
begin
test := TMyThread.Create(False);
//等待线程结束
while WaitForSingleObject(test.Handle, 0) <> WAIT_OBJECT_0do
Application.ProcessMessages;
ShowMessage('Thread Terminated!');
//Continue your process...
end;