Re: Closing out threads



On Fri, 31 Aug 2007 19:10:00 -0700, ModelBuilder
<ModelBuilder@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

How are you currently telling the function running the thread, from the main
app, that the function needs to exit?

Probably in a most inappropriate way. :-)

I have a "Start" button to start the thread (though I may end up
initialize the thread on startup and communicating what it needs to
do.) When the button is pushed I change the button text to
"Working!", start the thread and return to the UI. When the button is
clicked again the event handler checks for the presence of the text
"Working!" and if it matches, changes the text to "Quitting!" and
exits (after setting a few other flags, IIRC.) The thread has a one
second sleep period built inside some outter loops and checks ever
second or so for "Working!" inside a loop. If there's no match a
break is initiated which causes the code to exit to the encompassing
loop which also checks for "Working!" When the outter loop finds it's
time to leave it changes the button text to "Start" and exits the
function.

It would seem that the executing function just needs to check the settings
as it progresses, rather than restarting it with new settings.

Which is probably the way I'll go. I didn't realize that threads are
sort of sticky once they're run. I'll have to build some surrounding
logic to tell it to reload the new parameters however.

You have my gratitude.

--
Lilith
.


Loading