July 2018
Beginner to intermediate
668 pages
16h 29m
English
The btnStart event creates 10 threads and puts each of them in a simple generic list declared as TObjectList<TFileWriterThread>. This list will be used to iterate over the threads when terminating or checking the status of threads. Threads are not configured with FreeOnTerminate, because we require a live reference to check their status.
The real work is done in the Execute method of TFileWriterThread. Let's check it out:
procedure TFileWriterThread.Execute; var I: Integer; NumLines: Integer; begin inherited; //decide how many numbers to write NumLines := 11 + Random(50); for I := 1 to NumLines do begin //wait a bit of time to simulate a higher workload TThread.Sleep(200); //acquire the lock on FStreamWriter. TMonitor.Enter(FStreamWriter); ...
Read now
Unlock full access