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 » Developing U++ » U++ Developers corner » Helper function to help dealing with GUI thread related issues
Helper function to help dealing with GUI thread related issues [message #43069] Fri, 02 May 2014 01:44 Go to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi all,

Doiing some corrections to an application I ran into the classic GUI thread Vs other thread (triing to do GUI things) problem

My problem was the following: I have an import thread that imports data into a DB and from time to time it needs to ask questions in order to solve conflics ... so it creates dialogs ... and this can only be done in GUI thread ( as stated in documentation, GuiLock is not sufficient for this ).
So I decided to do a helper function that can be used by others, it does the following:

* Puts the originating thread in wait state
* runs the dialog in the GUI thread
* Once the dialog finished, it releases the originating thread

All you need to use it is a Callback to the GUI action you need to be done, all the synchronisation is done automatically

void GuiExecWait(Callback cb, int execDelay_ms = 20) {
	Mutex mtx;
	mtx.Enter();
	{
		// enter new context to avoid mtx destruction before cond destruction ( due to bad compiler optimizations )
		ConditionVariable cond;
		cb << callback( &cond, &ConditionVariable::Signal );
		SetTimeCallback(execDelay_ms, cb);
		cond.Wait(mtx);
	}
}


Maybe this helper function can be added to core ?

[Updated on: Fri, 02 May 2014 01:45]

Report message to a moderator

Re: Helper function to help dealing with GUI thread related issues [message #43070 is a reply to message #43069] Fri, 02 May 2014 07:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I would say that it is pretty much the same thing as Ctrl::Call, except the delay, which I do not quite understand what is supposed to be used for.

Mirek
Re: Helper function to help dealing with GUI thread related issues [message #43082 is a reply to message #43070] Sat, 03 May 2014 23:06 Go to previous message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Ohhh !! I never knew such a function existed.
I guess the only good part about my post is that other people know it exist now Very Happy

NB: The delay was to avoid having signal() called before cond.wait() was called but it's true that since a gui action is supposed to be launched (and it therefore waits for a user action ) the delay is useless ( but just in case )

Thanks for the reply
Previous Topic: Skylark: Should escape character '$' be replaced to avoid name clash with Jquery?
Next Topic: How to manage UPP namespace
Goto Forum:
  


Current Time: Fri Apr 19 09:41:54 CEST 2024

Total time taken to generate the page: 0.01458 seconds