I am running a thread from a dialog which is making a GET request to check for updates. So I followed the guide here https://docs.wxwidgets.org/trunk/classwx_thread.html. The only difference from there is that the handler had to be changed from EVT_COMMAND to EVT_THREAD. I get a compilation error in the event handler if I try to use EVT_COMMAND which is what is in the documentation. I found on another post here to EVT_THREAD and it compiled fine...
My problem is that I can see the thread runs and when it completes it sends a event to the handler via wxQueueEvent, but the dialog handler function is not being executed when the event gets sent. I have verified that (through wxLogDebug statements) it does queue the event and exits the Entry function of the thread.
I have also defined my custom event to handle the thread completion event. I have done custom events before, but I haven't done this with threads yet so I wonder what I'm doing something wrong...
Code: Select all
wxDEFINE_EVENT(CHECK_UPDATE_THREAD_COMPLETED, wxThreadEvent);
wxThread::ExitCode CheckForUpdateThread::Entry()
{
std::string eventString = "";
while (!TestDestroy()) {
// check for update (omitted for brevity)
}
auto event = new wxThreadEvent(CHECK_UPDATE_THREAD_COMPLETED);
event->SetString(eventString);
wxQueueEvent(pHandler, event);
return (wxThread::ExitCode) 0;
}
// CheckForUpdateDialog
wxBEGIN_EVENT_TABLE(CheckForUpdateDialog, wxDialog)
// ...
EVT_THREAD(CHECK_UPDATE_THREAD_COMPLETED, CheckForUpdateDialog::OnThreadCompletion)
wxEND_EVENT_TABLE()