线程对象的FreeOnTerminate属性,到底有什么作用啊?我这么做:hread1:=tmyhread.create(false);(hread为全局)这个线程中的Execute过程被执行完后线程对象会被释放也就是不能再
用hread.Resume再次使用这个线程对象,而是要用create再建一个而即使我这么做:
hread1:=tmyhread.create(true);(hread为全局)
hread1.freeonterminate:=false;
hread1.Resume
结果也是一样,这个对象运行完后还是会被释放?哪位前辈能举个例子指点我一下FreeOnTerminate的具体作用吗?谢了!!!

解决方案 »

  1.   

    Determines whether the thread object is automatically destroyed when the thread terminates. property FreeOnTerminate: Boolean;DescriptionSet 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的时候,必须手动释放。
      

  2.   

    FreeOnTerminate为true ,线程的Execute执行完后,会自动释放资源的。
    所以我的多线程程序中,一般在Execute中设置一个变量,让线程的Excute事件一直循环着(即使什么也不干),当确实要退出时,改变变量的状态,这时线程自动结束,并释放资源。