I’ve got a background thread that is polling a server. When there’s data, I want to handle the data on the UI thread. If I store the hwnd of the main window.
How can I get a particular method static void DataHandler(void* data) to be executed on the UI thread?
I think creating a timer passing the hwnd and the function pointer would work. But is there a better way? Can I use PostMessage to somehow get the datahandler invoked.
Also, I’m not writing the UI code, so I don’t have the ability to modify anything in the message loop.
One thing that you could do – use an inter-thread signalling object perhaps as simple as a boolean flag. When data appears on the server polling thread, you can signal the flag. You could check for this flag in the message loop of your UI thread. Alternatively, you could just send the UI thread a custom window message.
Now that I re-read your question – since you can’t change the UI code, this approach wouldn’t work. You could use the WIN32 API to add your own custom message hook function to fix this problem.