Executing Thread Objects
Go Up to Executing thread objects Index
Once you have implemented a thread class by giving it an Execute method, you can use it in your application to launch the code in the Execute method. To use a thread, first create an instance of the thread class. You can create a thread instance that starts running immediately, or you can create your thread in a suspended state so that it only begins when you call the Resume method. To create a thread so that it starts up immediately, set the constructor's CreateSuspended parameter to False. For example, the following line creates a thread and starts its execution:
SecondThread := TMyThread.Create(false); {create and run the thread }
TMyThread *SecondThread = new TMyThread(false); // create and run the thread
You can create multiple instances of the same thread type to execute parallel code. For example, you can launch a new instance of a thread in response to some user action, allowing each thread to perform the expected response.
The following topics discuss how to use the threads in your application: