Well, Two options..

1. write very granular threaded code, and dont call procedures that are not
also granular and make sure they all support a cancel callback. when writing
threads, I tend to only use them in a way that allows me to finish it in a
timely fashion.

eg


while not terminated do
begin
  do500things(cancelcallback)
end;

function cancelcallback:boolean;
begin
  result := terminated;
end;

procedure do500things
begin
  for x := 1 to 500 do
    if CancelCallback then exit else dosomethingsmall
end;


if you really cant make it granular, then set the thread to do a
freeonterminate. when you kill the thread, dont use free, or waitfor..
instead keep some state tracking and call terminate from your cancel button,
you can handle cleanup from the onterminate event later.

On Feb 1, 2008 2:52 PM, Phil Scadden <[EMAIL PROTECTED]> wrote:

>
> > 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
> >
> What about just calling the SDK TerminateThread using the thread handle?
>
> --
> Phil Scadden, Senior Scientist GNS Science Ltd 764 Cumberland St,
> Private Bag 1930, Dunedin, New Zealand Ph +64 3 4799663, fax +64 3 477
> 5232
>
> Notice: This email and any attachments are confidential. If received in
> error please destroy and immediately notify us. Do not copy or disclose the
> contents.
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: [email protected]
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to [EMAIL PROTECTED] with
> Subject: unsubscribe
>



-- 
Kyley Harris
Harris Software
+64-21-671-821
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: [email protected]
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to [EMAIL PROTECTED] with Subject: unsubscribe

Reply via email to