Introduction to Delphi Threading and its Create method

Source: Internet
Author: User

TThread's statement in the classes unit is as follows

Type TThread = Class private fhandle:thandle;        Fthreadid:thandle;        Fterminated:boolean;        Fsuspended:boolean;        Ffreeonterminate:boolean;        Ffinished:boolean;        Freturnvalue:integer;        Fonterminate:tnotifyevent;        Fmethod:tthreadmethod;        Fsynchronizeexception:tobject;        Procedure Callonterminate;        function getpriority:tthreadpriority;        Procedure setpriority (value:tthreadpriority);    Procedure setsuspended (Value:boolean); protected procedure Doterminate;        Virtual Procedure Execute; Virtual        Abstract        Procedure Synchronize (Method:tthreadmethod);        Property Returnvalue:integer read Freturnvalue write Freturnvalue;    Property Terminated:boolean read fterminated;        Public constructor Create (Createsuspended:boolean); destructor Destroy;        Override        Procedure Resume;        Procedure Terminate;        function Waitfor:integer; PropeRty Freeonterminate:boolean Read Ffreeonterminate write ffreeonterminate;        Property Handle:thandle read Fhandle;        Property priority:tthreadpriority read GetPriority write setpriority;        Property Suspended:boolean read fsuspended write Suspended;        Property Threadid:thandle read Fthreadid;    Property Onterminate:tnotifyevent read Fonterminate write fonterminate; End

  

When TThread's Create () is called, it is necessary to pass a Boolean parameter createsuspended. If this parameter is set to False, execute () is automatically called when Create () is called, which is the thread code that executes automatically. If this parameter is set to True, you need to run TThread's resume () to wake the thread.

  In general, when you call Create (), there are some additional property requirements to set. Therefore, you should set the createsuspended parameter to true, because setting the TThread property in TThread has been performed can cause trouble.

At a deeper point, a RTL routine beginthread () is implicitly called in the constructor Create (), and it calls an API function CreateThread () to create an instance of a thread object. The createsuspended parameter indicates whether the CREATE_SUSPENDED flag is passed to CreateThread ().

Introduction to Delphi Threading and its Create method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.