CnPack Forum


 
Subject: bpl内线程怎么退不出来
niaoge
灌水司司长
Rank: 6Rank: 6



UID 9910
Digest Posts 0
Credits 438
Posts 143
点点分 438
Reading Access 10
Registered 2007-4-8
Status Offline
Post at 2007-8-25 18:21  Profile | Blog | P.M. 
bpl内线程怎么退不出来

在运行时 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;
Top
skyjacker
版主
Rank: 7Rank: 7Rank: 7
茶农


UID 2239
Digest Posts 9
Credits 617
Posts 269
点点分 617
Reading Access 100
Registered 2006-6-8
Status Offline
Post at 2007-8-27 22:19  Profile | Blog | P.M.  | QQ
我不知道你说的 bpl内线程 与普通线程有什么区别。

我想知道你想在 TxxThread.Destroy 里干什么。




一壶清茶煮青春.
Top
niaoge
灌水司司长
Rank: 6Rank: 6



UID 9910
Digest Posts 0
Credits 438
Posts 143
点点分 438
Reading Access 10
Registered 2007-4-8
Status Offline
Post at 2007-8-29 01:29  Profile | Blog | P.M. 
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;

这是rem内的,怎么改都退不出来,我只好把多线程的这块分出来,不放在bpl内,其它的合做成一个静态包bpl
以前不相信多线程不能打包到bpl内,通过自己做才相信了这点,不是退不出来,就是内存报错,
注:这段代码放在exe内,不会报错

[ 本帖最后由 niaoge 于 2007-8-29 01:32 编辑 ]
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6756
Posts 3554
点点分 6756
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2007-8-29 14:27  Profile | Blog | P.M. 
WaitFor的时候会再次触发Destroy?
Top
AdamWu
新警察
Rank: 1



UID 28253
Digest Posts 0
Credits 4
Posts 2
点点分 4
Reading Access 10
Registered 2007-10-10
Status Offline
Post at 2007-10-10 05:05  Profile | Blog | P.M. 
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.
Top
 




All times are GMT++8, the time now is 2024-4-25 00:35

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.006604 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP