线程对象的FreeOnTerminate属性,到底有什么作用啊?

zxr56066909 2003-05-30 10:43:25
线程对象的FreeOnTerminate属性,到底有什么作用啊?我这么做:

hread1:=tmyhread.create(false);(hread为全局)

这个线程中的Execute过程被执行完后线程对象会被释放也就是不能再
用hread.Resume再次使用这个线程对象,而是要用create再建一个

而即使我这么做:
hread1:=tmyhread.create(true);(hread为全局)
hread1.freeonterminate:=false;
hread1.Resume
结果也是一样,这个对象运行完后还是会被释放?

哪位前辈能举个例子指点我一下FreeOnTerminate的具体作用吗?谢了!!!
...全文
1265 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chw_csdn_chw 2003-05-31
  • 打赏
  • 举报
回复
FreeOnTerminate为true ,线程的Execute执行完后,会自动释放资源的。
所以我的多线程程序中,一般在Execute中设置一个变量,让线程的Excute事件一直循环着(即使什么也不干),当确实要退出时,改变变量的状态,这时线程自动结束,并释放资源。
l_xiaofeng 2003-05-30
  • 打赏
  • 举报
回复
Determines whether the thread object is automatically destroyed when the thread terminates.

property FreeOnTerminate: Boolean;

Description

Set FreeOnTerminate to True if you don抰 want to explicitly destroy threads after they finish executing. When FreeOnTerminate is False, the thread object must be explicitly destroyed in application code.

Warning: When FreeOnTerminate is True, the Execute method may run and then free the thread before your application can execute the next line of code. Thus, you should not call any methods of the thread object when FreeOnTerminate is True unless you create the thread in a suspended state.

决定是否当线结束的时候 , 线物体自动地被释放。


在线程运行之後设定 FreeOnTerminate 为真 , 则执行以后释放。 当 FreeOnTerminate 为FALSE的时候,必须手动释放。

zxr56066909 2003-05-30
  • 打赏
  • 举报
回复
我要的是例子说明前后的不同到底在哪,你搬这些东东出来干吗?

5,930

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧