The core of the solution was to make
Code: Select all
class ThreadEvtHandler : public wxEvtHandler
also ProcessThreadEvent had to be overridden since AddPendingEvent isn't virtual. ProcessThreadEvent isn't used anywhere in the wxWidgets library but can be used by the user.
In constructor we have to create new list so that ProcessPendingEvents doesn't fail.
Code: Select all
m_pendingEvents = new wxList();
Then CommandThread is defined like this:
Code: Select all
class CommandThread : public ThreadEvtHandler, public wxThread
Then Entry() looks like this:
Code: Select all
while (!TestDestroy())
{
m_SemaphoreEvtReady.WaitTimeout(100);
ProcessPendingEvents();
}
1.) ::wxPostEvent cannot be used, as it calls wxEvtHandler::AddPendingEvent and AddPendingEvent isn't virtual
Use AddPendingEvent directly.
2.) ProcessEvent() cannot be used directly for synchronous event processing, as the event will be processed in the current thread.
This means event processing chains spanning multiple threads will not work as you might expect.
3.) Note that CommandThread cannot have event handlers for example for button or mouse events from other windows, they have to be in the window they belong to. If you try to create event handler chains (using SetNextHandler) it won't work properly either as it will run into problem 2.) with ProcessEvent().
How it should be used:
- to send events from one thread to another using AddPendingEvent, the advantage over custom processing using simple queues in wxThread is that you can use event macros and Connect() if you use CommandThread