

Lets see an example of thread which find list of prime numbers till give number and save into a file.įunction IsPrime(iNum: integer): boolean

And a Thread will terminate automatically or we can terminate manually as per required. Then we can start a thread to perform some other actions. Then we can create the object of this class to create a new thread. So we have to create a new class by inheriting from this class and need to implement Execute method. How ever we cannot create TThread class objects directly as it is an abstract class. It provides options for creating threads, executing threads and terminate when required.
/cdn.vox-cdn.com/uploads/chorus_image/image/71445911/1429774943.0.jpg)
To create and execute a separate Thread in application, Delphi provides TThread class which is an abstract class. Threads allow you to ensure that I/O operation should not delay unrelated parts of your application. Doing I/O work : I/O to disk or to network can have unpredictable delays. Doing background processing : Some tasks may not be time critical, but need to execute continuously. As a result, the display cannot be updated. Doing lengthy processing : When a windows application is calculating it cannot process any more messages. Here are some examples where we might use threads. Threads are mostly used in case of performance related problems. So in this case copy process is going on in a new thread which is not effecting to main thread. For an example in windows explorer we are copying a large volume of data from one folder to another folder and we found it will take long time but during copy we can do other work also. And Thread is generally used to perform several set of actions at once in situations like some actions may cause a considerable delay but during that period the program should be able to perform other actions too. In a Process many actions can be performed one by one on fast in fast perform order. So first lets go about Process, Process is a program that runs on a system and uses system resources like CPU, Memory etc.
