Is there a way to handle multiple events at the same time? Topic is solved
Is there a way to handle multiple events at the same time?
Say I have an application which I would like to display a count down on it, at the same time I want to execute some other codes. In this case, I notice that the OnTimer handler won't work correctly. (I may be wrong but I think it is ridiculous for the count down to stop when I am busy handling a button click)So how can I fix this ?
Re: Is there a way to handle multiple events at the same time?
The only workaround would be to call ::wxYield() regularly in the button event handler, so that other events can get processed.
Or you need to move the long-running code to a separate thread.
Or you need to move the long-running code to a separate thread.
Use the source, Luke!
Re: Is there a way to handle multiple events at the same time?
Thanks. Speak of multi-threading, I want to know what will happen if I try to call the render function in another thread when wxwidgets is already busy rendering? For example, I want to wait until a package is received from the net and then display something. How can I do this? Can I call SetLabelText directly in this thread? Or there are other ways?
Last edited by HansLjy on Fri Jun 25, 2021 12:29 pm, edited 1 time in total.
Re: Is there a way to handle multiple events at the same time?
GUI operations must only happen in the main thread.
Use the source, Luke!
Re: Is there a way to handle multiple events at the same time?
I see. But I was wondering how this could be implemented: I want to wait for a signal from external source and display a text after that (at the same time I want the count down to continue). How can I tell wxWidgets it's time to refresh?
Re: Is there a way to handle multiple events at the same time?
No.Can I call SetLabelText directly in this thread?
There are three main ways to handle this situation.
1) Send an event to the main thread
2) Use wxMessageQueue to communicate with the main thread (you'll need a timer event that regularly checks the queue, or combine it with 1) ) https://docs.wxwidgets.org/trunk/classw ... _01_4.html
3) Use wxEvtHandler::CallAfter() to call some code asynchronously in the main thread. (I would use this only for small code snippets ) https://docs.wxwidgets.org/trunk/classw ... 50b3719519
Use the source, Luke!