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   |
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
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
|
|
|
Goto Forum:
Current Time: Sat May 10 21:28:06 CEST 2025
Total time taken to generate the page: 0.04096 seconds
|