wxyield usage

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

wxyield usage

Post by coderrc »

I have a Long Running Task (~10 seconds) that necessarily blocks the UI.
Basically there is a block of data which is retrieved from a server which the UI needs in order to function. In the event that the data needs to be retrieved from the server, I display a window with a loading message and a wxGauge set to indeterminate mode.
Of course the actual work is done in a thread, but I need the data in order to proceed, so I wait for it...in the UI thread... :cry:

the LRT runtime basically looks like this

Code: Select all

MyTask task;
while(!task.iscomplete()){
    wxyield();
    sleep_ms(25);
}
return task.data;
My problem is that the wxGauge doesnt pulse, even after adding wxyield to the LRT.
the gauge is set to pulse on a timer and works fine in other instances.
Bind(wxEVT_TIMER, [&](wxTimerEvent&) {m_gauge->Pulse(); }, m_timer.GetId());

Am I not using wxyield correctly or something?
The only reason I even bother asking is because I know that I have seen this work. :? IIRC it was working right up until I switched from gtk3 to gtk2.

I am also aware that this is not the proper way to handle this situation, but realistically, this is an edge case that isnt likely to ever appear in the wild.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxyield usage

Post by doublemax »

Does the timer event handler get executed? I would move the Pulse() into the while-loop.
I am also aware that this is not the proper way to handle this situation, but realistically, this is an edge case that isnt likely to ever appear in the wild.
If the user can't do anything useful while the task is running, this is a valid way. I did this several times. The only difference is that i used a wxProgressDialog instead of a wxGauge in the main GUI.
Use the source, Luke!
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: wxyield usage

Post by coderrc »

yes, the handler gets executed.
I can write to the console and such, but the gauge doesnt progress, in this particular use only.

Its just one of those weird things i guess.
Post Reply