"Vladimir Stefanovic" < XXXX@XXXXX.COM > writes:
If SyncAlphaBlend is running in the main thread (due to Synchronize),
then the only time the GUI would be responsive is in between calls to
Synchronize, unless SyncAlphaBlend runs the event loop periodically to
avoid starvation. If that's the case however, that may be your
problem, because it can delete the object before the code running in
that object has completed.
The main form should wait for the thread to complete before deleting
it. If the thread is running a nested event loop in a Synchronize
call, it must check the Terminated property immediately after
returning from the call to Synchronize, and properly break immediately
if it's true.
I can't say with certainty what is causing your problem since your
exmaple is incomplete.
However, be sure to always start the thread suspended, to prevent
issues of the thread being spawned before the TThread object's
constructor has completed, and other similar problems. Then set the
Suspended property to "false" when you want it to start running. This
makes it impossible to run into that problem (which may not be yours,
but I simply don't know.)
But in a nutshell, if every time you call Synchronize you check the
Terminated property and immediately stop doing more calculations, your
thread should exit quickly. Then it's safe for the main thread to do
a WaitFor on the thread object that it asked to terminate.