OK I’m writing a Zoom component and I wanted it to capture from screen within a secondary thread.
You can pretend I just want to derive TThread in an empty component. I didn’t write any codes in the thread so it is just a simple useless thread. I wrote this code: Thrd := TCaptureThread.Create(False); in the component main class.
Then I wrote Thrd.Free in the main class destruction code. Now when I close the whole application, although it destroys everything, the process doesn’t terminate completely. In Windows Task Manager shows that number of threads is 1 but the process remains. If I comment the thread creation line, everything becomes OK and application terminates quickly. What am I gonna do about this? 🙁
Thanks in advance
When you call
Thrd.Freethe following code fromTThread.Destroyis run:Calling
Freeon a thread will thus terminate the thread synchronously.My guess is that the call to
WaitFornever returns. PerhapsTCaptureThread.Executedoesn’t checkTerminatedand exit. PerhapsTCaptureThreadis waiting on the main thread and so the wait on the thread deadlocks.It’s pretty hard to do anything other than guess, based on your question, but I’d want to check whether or not your code gets past the
WaitForcall in the destruction ofThrd. Enable Debug DCUs, set a breakpoint one the call toWaitForand see for yourself.