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 » U++ Library support » U++ Widgets - General questions or Mixed problems » ASSERT(IsMainThread());
ASSERT(IsMainThread()); [message #21420] Tue, 19 May 2009 13:56 Go to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Hello Mirek!

I have an error on run a builded application in line
 ASSERT(IsMainThread());

from uppsrc/Ctrl/CtrlCore/Win32Wnd.cpp in method
void Ctrl::GuiSleep(int ms)
.

What i do wrong? some days ago works fine, but after you added this line its prompt error! Tell me how can I change my code?

The situation is: I call a function in a thread instance, and this function works with GUI (progress). I uses this in GoogleTranslator that I call function in thread for translate a text

this is full method:
void Ctrl::GuiSleep(int ms)
{
	GuiLock __;
=>HERE	ASSERT(IsMainThread());
	ELOG("GuiSleep");
	if(EndSession())
		return;
	ELOG("GuiSleep 2");
	int level = LeaveGuiMutexAll();
#if !defined(flagDLL) && !defined(PLATFORM_WINCE)
	if(!OverwatchThread) {
		DWORD dummy;
		OverwatchThread = CreateThread(NULL, 0x100000, Win32OverwatchThread, NULL, 0, &dummy);
		ELOG("ExitLoopEventWait 1");
		ExitLoopEvent().Wait();
	}
	HANDLE h[1];
	*h = ExitLoopEvent().GetHandle();
	ELOG("ExitLoopEventWait 2 " << (void *)*h);
	MsgWaitForMultipleObjects(1, h, FALSE, ms, QS_ALLINPUT);
#else
	MsgWaitForMultipleObjects(0, NULL, FALSE, ms, QS_ALLINPUT);
#endif
	EnterGuiMutex(level);
}


Add:
I added GoogleTranslator as example.

After build and run application press Translate button for generate error!

[Updated on: Tue, 19 May 2009 17:11]

Report message to a moderator

Re: ASSERT(IsMainThread()); [message #21425 is a reply to message #21420] Tue, 19 May 2009 17:45 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, I have fixed this, although I am not quite sure if there is any good use to call GuiSleep from non-main thread:

GuiSleep waits at most given time, but waiting stops if there are any input events (like MouseDown) to be processed. Anyway, processing messages is always performed by the main thread, so it is questionable why is GuiSleep good for non-mains.

Mirek
Re: ASSERT(IsMainThread()); [message #21427 is a reply to message #21425] Tue, 19 May 2009 19:06 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

luzr wrote on Tue, 19 May 2009 18:45

Well, I have fixed this, although I am not quite sure if there is any good use to call GuiSleep from non-main thread:

GuiSleep waits at most given time, but waiting stops if there are any input events (like MouseDown) to be processed. Anyway, processing messages is always performed by the main thread, so it is questionable why is GuiSleep good for non-mains.

Mirek

In base my example what is the solution?
Re: ASSERT(IsMainThread()); [message #21490 is a reply to message #21425] Fri, 22 May 2009 16:53 Go to previous message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Thank you Mirek for correct GUISleep method;

Very interesting realization of the method void
Ctrl::Call(Callback cb) !
Previous Topic: Global shortcut (Keyboard event) handle
Next Topic: Where to add event function in theide
Goto Forum:
  


Current Time: Fri Apr 19 21:06:32 CEST 2024

Total time taken to generate the page: 0.06036 seconds