I'm new at message queueing, and want to implement something like this:
Get information from main thread
Send to a worker thread queue
Worker thread may just process it or send to another work thread proccess it
Eventually callback execution to UI due some events (can handle it with synchronize mechanism)
My main problem is how to make communication between main thread and worker thread's, and between worker threads with other worker threads (to signal the main thread eventually, I can callback then synchronized).
After tons of googling, I found basically two ways to do it:
- Create a message-only
HWND
, which exchange messages between a registeredWndProc()
function. I found a perfect example of that here. As Remy Lebeau commented, this way may need to dispatch the message viaDispatchMessage()
(and seems to be more verbose way to do it). This way basically I use thePostMessage()
function and process messages in theWndProc()
function.
Or:
- Create a custom
TThread
-derived class with aPeekMessage()
|GetMessage()
loop which processes thread messages and deals with what it needs to do in itsExecute()
method. This one basically I use thePostThreadMessage()
function and process messages in theExecute()
method of the thread;
I successfully tested a basic demo with the two options, receiving the messages in the two ways I mentioned.
For those who have more expertise, am I on the right track? Did I miss something trying to understand how to do this?
Another question for those more experienced is, which method is the best for heavy message exchanging? And which is the best for an X situation or Y situation?
It's a more theoretical question, but thanks for those who can help.