Home » Community » Newbie corner » Shutdown procedure by clicking red x
Re: Shutdown procedure by clicking red x [message #30330 is a reply to message #30120] |
Fri, 24 December 2010 23:45   |
alendar
Messages: 47 Registered: January 2010 Location: Idaho, USA
|
Member |
|
|
Hi Neil,
I used this technique to interrupt a thread at closing time:
enum ListLoaderEnum {LL_RESET, LL_KILLLOAD};
class MainWin : public WithMainLayout<TopWindow> {
protected:
StaticMutex loadListLock;
Thread listLoaderThread;
volatile Atomic stopFetchingTags;
public:
MainWin() : stopFetchingTags(0) {
virtual void Close() {
// While we are in the Close event, no threads can continue, so a Wait will lock up the system
// Notify threads to stop, then trigger a callback
int x = listLoaderThread.GetCount();
if (x) {
loadListLock.Enter();
stopFetchingTags = LL_KILLLOAD;
loadListLock.Leave();
this->ProcessEvents();
Sleep(100);
PostCallback(THISBACK(Close));
} else {
TopWindow::Close(); // Won't close unless this is called
}
}
void EnrichDbFromTags() {
listLoaderThread.Run(THISBACK(EnrichDbFromTagsThread));
}
void EnrichDbFromTagsThread() {
stopFetchingTags = LL_RESET;
...
while(lst.Fetch()) {
if (stopFetchingTags == LL_KILLLOAD) {
break;
}
...
}
}
I tried the Thread::IsShutdownThreads() but it just locked up tight. The StaticMutex is probably overkill.
Jeff
cd7651feeb698f6ac6cec1f6deda5e5b
|
|
|
Goto Forum:
Current Time: Mon Apr 28 20:53:24 CEST 2025
Total time taken to generate the page: 0.01441 seconds
|