[SOLVED] Thread Start / Execute lazarus / 21-General ---------------------------------------------------------------------- pcurtis · 2021-02-03 12:51 Hi All, I create a thread, MyThread, with FreeOnTerminate := false I start the thread with MyThread.Start, which calls the procedure TMyThread.Execute. Execute ends. I don't free MyThread, but if I try to Start the thread again, MyThread.Start, nothing happens. Whats wrong? ---------------------------------------------------------------------- MarkMLl · 2021-02-03 13:01 How on earth do you expect us to know without showing us your code? MarkMLl ---------------------------------------------------------------------- rvk · 2021-02-03 13:12 You can't (and shouldn't) use TThread.Start multiple times. TThread.Start is only used when you create the thread in suspended state and want to start it. It is not used to "resume" an already ended thread. ---------------------------------------------------------------------- pcurtis · 2021-02-03 13:55 @RVK Does that mean a thread is a one shot thing? ---------------------------------------------------------------------- rvk · 2021-02-03 14:02 Quote from: pcurtis on February 03, 2021, 02:55:18 pm@RVK Does that mean a thread is a one shot thing? Or a long running thing  Why did your .Execute of your thread end? Why don't you put whatever you do in the thread in a loop (with "while not Terminated")? You could also put a flag in (boolean) to do something and if that flag is not set just sleep the thread. ---------------------------------------------------------------------- pcurtis · 2021-02-03 14:07 I was going to download web pages, and just learning. Thanks anyway. ---------------------------------------------------------------------- rvk · 2021-02-03 14:11 Quote from: pcurtis on February 03, 2021, 03:07:46 pmI was going to download web pages, and just learning. Thanks anyway. In that case you can create a new thread. For webpages you can also create a queue from which multiple threads (i.e. 4 or 8 threads) get their URL to download from. Lots of options. ---------------------------------------------------------------------- cdbc · 2021-02-03 17:47 Hi Have a look at TThread, it's got a private field called terminated which is readonly, which means, you can't tamper with it. Once you call terminate it toggles this field to true, then call start -> execute which tests the terminated property and exits immidiately... HTH Regards Benny ---------------------------------------------------------------------- Remy Lebeau · 2021-02-03 18:18 Quote from: pcurtis on February 03, 2021, 02:55:18 pm@RVK Does that mean a thread is a one shot thing? Yes.  Once Execute() exits, the thread is ended, it cannot be restarted.  All you can do at that point is free the thread and create a new one. If a thread needs to run its Execute() logic multiple times, run that code in a loop, then exit Execute() when the loop is finished. ---------------------------------------------------------------------- pcurtis · 2021-02-04 09:35 OK. Thanks all.