wxCallAfter for C++
Noel
NoelByron at gmx.net
Wed Jun 6 04:02:50 PDT 2007
It schedules a function call to the event loop of the application. I
try to sketch out a C++ scenario:
A arbitrary thread has finished a lengthy operation and wants to pass
the result to the application that usually (at least in my
applications) runs most of the application logic. Now, the thread
could call a method directly passing its result. The drawback is that
this method is called in the threads context and you have to consinder
a lot of concurrency issues then. Something I'm definitly not good at.
On the other hand the thread could create a function object and bind
the result to the object (the function is not called yet). I'm looking
at Boost at the moment but I would prefer a more wx like solution
maybe with wxVariants... Then the thread sends a EVT_CALL_AFTER event
(TM ;o) (which has a pointer to the function object attached) to the
main thread/window.
The GUI thread would receive the event in its context, take the
function object from the event parameter and call it. This way the
function that processes the result of the thread operation is called
in the GUI thread context and even the result does not need to be
synchronised.
I hope I managed to bring over the problem and the idea.
Best regards,
Noel
More information about the wx-users
mailing list