[DUG] Terminating a thread

Phil Middlemiss phil at tumonz.co.nz
Thu Sep 21 12:05:08 NZST 2006


Use the Terminate Method of the thread (as you do in the sample code for 
button2). Then in your thread's execute method you need to regularly 
check the thread's Terminated method.

eg:

While not Terminated do
  begin
    //task
  end;
  if not Terminated then
    begin
    end;

etc etc


Phil.

Nick Fauchelle wrote:
> Hey guys,
>
> I got a thread here (TFetchData = class(TThread)) which downloads a 
> bunch of xml and then process's it and sticks it into a database.
> All working well, however I want the user to be able to 
> abort/terminate the process...
>
> So one think I did is setup a global varaible - gbTerm : boolean;
> And in my thread.execute I would do this
> If gbTerm = true then terminate;
>
> However that didn't quite work as expected (ie, nothing happened, 
> thread still ran).
>
> So then I tried
>
> var
> MyThread : TFetchData;
> begin
> MyThread := TFetchData.create('myname');
> end;
>
> button2
> begin
> MyThread.Terminate;
> end;
>
> same result as above (to be expected ofc).
>
> So im just wondering... how should I terminate this thread?
>
> Thanks
> Nick
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: phil.vcf
Type: text/x-vcard
Size: 250 bytes
Desc: not available
Url : http://ns3.123.co.nz/pipermail/delphi/attachments/20060921/25a621ca/phil.vcf


More information about the Delphi mailing list