c++multithreadinguser-interfaceeventswxwidgets

Event publishing from wxThread to wxWidgets Application


In my wxWidgets application, I do:

  1. Disable all "User" widgets.
  2. Create a thread to read, parse and store data from a file.

I want to send a message (event?) to the main application from the thread indicating that all the processing of the data is finished (so that the application can enable all the "User" widgets).

I'm using wxThread for the thread.

I don't want the application GUI to freeze while the thread is running.

The examples I have found on the internet are for sending events from the application.

In the embedded systems world, this is usually accomplished by posting to a message queue, then the task wakes up and processes the message from the queue.

My question is: how to send an event or notification from a wxThread to a wxApplication?


Solution

  • See wxQueueEvent for safely posting an event from a secondary thread to an event handler, to be handled in the main thread.

    Examples using it are in samples folder of wxWidgets. One is samples/thread/thread.cpp.