Show: Delphi C++
Display Preferences

System.Classes.TThread.FreeOnTerminate

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property FreeOnTerminate: Boolean read FFreeOnTerminate write SetFreeOnTerminate;

C++

__property bool FreeOnTerminate = {read=FFreeOnTerminate, write=SetFreeOnTerminate, nodefault};

Properties

Type Visibility Source Unit Parent
property public
System.Classes.pas
System.Classes.hpp
System.Classes TThread

Description

Determines whether the thread object is automatically destroyed when the thread terminates.

Set FreeOnTerminate to true if you don't 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 is best left for threads that simply perform a task and then naturally terminate. If you want to communicate with the thread or otherwise interact with it, including telling it when to terminate, FreeOnTerminate should never be used.

Calling Free on a TThread will set Terminated := True and then block until the thread terminates. You can use FreeAndNil() in the case where you want the variable set to nil. When Free returns, the thread is dead, gone, and the TThread instance is no longer valid. You can call Terminate at any time and any number of times (it only sets the property, Terminated := True). If Terminated is already True, calling Free will simply call it again, which doesn’t violate the previous sentence. It will block the caller until the actual thread itself terminates.

See Also


Code Examples

Personal tools
In Other Languages
Previous Versions
Assistance