Multithreading – restart Delphi TThread throughout the application lifecycle
I created a class derived from TThread because I wanted to do something asynchronous, but in order to avoid creating another class, I built the whole thing around the thread class I'm not sure if this is a good practice. If I can't make it work, then I think I have no choice but to recode
Problem: I create thread on formcreate, assign some properties, and then release it on formdestroy In the constructor of thread, I set freeonterminate = false When I click the button on the form, I start (); Thread OK, so it runs as expected, with errors (expected!), It was passed to my error handling event and it seemed to terminate Then I click the button again, and I get a thread error that cannot call start on a running or suspended thread
How do I complete a thread without releasing it and let me restart it?
Solution
You cannot restart the thread after completion / termination In this case, if the thread creates a new instance again as in formcreate