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 » The right way to use CoDo with GuiLock? (The app freeze when trying to update the GUI while CoDo)
Re: The right way to use CoDo with GuiLock? [message #58550 is a reply to message #58549] Sun, 12 June 2022 18:12 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1206
Registered: August 2007
Senior Contributor
Quote:

Is there any approach to CoWork for updating the ColumnList as every worker finish? instead of waiting till all of them are finished to update.


Not with CoDo or CoFor, no. (Not that I know of, at least)

The reason is, you'll need a non-blocking way so that the GUI can be refreshed, and events are processed.
Fortunately, there are several ways to do that.

But since you want a loop paralellization, you can do it using the CoWork::Do0 // Which is called by CoDo, anyway.

Here's how:

void CoTest::CoForTest2()
{
	list.Clear();
	CoWork co;

	std::atomic<int> ii(0);
	
	co.Do0([=, &ii] { // This is non blocking.. (i.e. will not wait for workers to compete their jobs)
		for(int i = ii++; i < 10000; i = ii++) {
			GuiLock __;
			list.Add(i);
		}
	},
	true);

	while(!co.IsFinished()) { // We'll use pseudo-blocking, so that we'll have control over the GUI event loop.
		ProcessEvents(); // Process the events.
		GuiSleep(20);    // Sleep right amount of time.
	}

}




Best regards,
Oblivion


 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Different File List
Next Topic: SVG for tool icon
Goto Forum:
  


Current Time: Sat May 10 21:28:06 CEST 2025

Total time taken to generate the page: 0.04096 seconds