在运行时 bpl内
destructor TxxThread.Destroy;
begin
//下面这段话...到结束 如果不加的话,exe关闭时就出错,加的话,又退不出来 ,请版主看看
if ModuleIsLib then
begin
if not FreeOnTerminate then
begin
FreeOnTerminate := true;
WaitFor;
Exit;
end;
end;
//结束
Terminate;
PMessages;
WaitFor;
inherited;
end;Author:
skyjacker Time: 2007-8-27 22:19
destructor TxxThread.Destroy;
begin
//下面这段话...到结束 如果不加的话,exe关闭时就出错,加的话,又退不出来 ,请版主看看
if ModuleIsLib then
begin
if not FreeOnTerminate then //判断是不是结束时退出
begin
FreeOnTerminate := true; //让结束时退出
WaitFor; //暂先不退出,等待这个线程的事情结束后由于FreeOnTerminate := true会再次触发 Destroy 以便执行下面代码
Exit;
end;
end;
//结束
Terminate;
PMessages;
WaitFor;
inherited;
end;
Because wait for will not set Terminated flag before calling WaitForSingleObject API, so your program will be stuck just before Exit.
Instead, I think you should call Terminate and then call Exit.