Well, Two options..<br><br>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.<br>
<br>eg<br><br><br>while not terminated do<br>begin<br> do500things(cancelcallback)<br>end;<br><br>function cancelcallback:boolean;<br>begin<br> result := terminated;<br>end;<br><br>procedure do500things<br>begin<br> for x := 1 to 500 do<br>
if CancelCallback then exit else dosomethingsmall<br>end;<br><br><br>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,<br>
you can handle cleanup from the onterminate event later.<br><br><div class="gmail_quote">On Feb 1, 2008 2:52 PM, Phil Scadden <<a href="mailto:p.scadden@gns.cri.nz">p.scadden@gns.cri.nz</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d"><br>> I have been using threads in applications for a while now, and one<br>> thing that always seems back to haunt me is stopping the thread.<br>> When using TThread you can call the Terminate procedure which simply<br>
> sets the FTerminated variable of the thread to True, which you then<br>> have to check for in your thread like<br>><br></div>What about just calling the SDK TerminateThread using the thread handle?<br><font color="#888888"><br>
--<br>Phil Scadden, Senior Scientist GNS Science Ltd 764 Cumberland St,<br>Private Bag 1930, Dunedin, New Zealand Ph +64 3 4799663, fax +64 3 477 5232<br><br>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.<br>
</font><div><div></div><div class="Wj3C7c"><br>_______________________________________________<br>NZ Borland Developers Group - Delphi mailing list<br>Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Kyley Harris<br>Harris Software<br>+64-21-671-821