[DUG] Stopping threads in applications
Nick
nick at salehoo.com
Mon Jan 28 14:03:23 NZDT 2008
Hi there :-)
I have been using threads in applications for a while now, and one thing
that always seems back to haunt me is stopping the thread.
When using TThread you can call the Terminate procedure which simply
sets the FTerminated variable of the thread to True, which you then have
to check for in your thread like
If Terminated = false then
begin
do stuff
end;
Which ok, can live with. But sometimes your doing something that wont
free up right away and might take 3-4+ seconds to stop. Now if your like
me when I click cancel / abort / stop I want the buttons and fields to
become active again, and not have to wait a while before this happens.
(ie, when starting a thread you might disable some input fields)
How do you handle threads? I guess it all depends on what it's doing etc.
Does it just mean should do more checking of If Terminated?
What do you do when your thread calls some procedure like so
...
if terminated = false then
begin
thread_safe_count_0_500;
end;
if terminated = false then
begin
...
the user is going to have to wait for that 0 to 500 procedure to finish,
before it then reaches the next If Terminated check.
Seems a bit mickey mouse.
Nick
More information about the Delphi
mailing list