Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
alendar is currently offline  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
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Copy\Paste Between Project Files Doesn't work
Next Topic: Error meaning
Goto Forum:
  


Current Time: Mon Apr 28 05:01:33 CEST 2025

Total time taken to generate the page: 0.02321 seconds