Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendMessage vs PostMessage 1

Status
Not open for further replies.

VincentP

Programmer
Apr 1, 2001
116
0
0
I am trying to build a multithreaded application in which one thread takes care of the GUI/displaying of the information, and the other thread creates the information to be displayed.

When I tried to send messages to main window using CWnd::postMessage, I realized that the messages are *not* procossed in the first in first out order. To avoid receiving my messages out of order, I decided to use SendMessage instead. Since this function waits for the end of the message's processing, then everything is received in order.

However, using SendMessage is sending me into a programming nightmare: I just can't get rid of all the deadlock situations which happen when the main thread has to wait for the working thread while the working thread is sending a message to the main thread... :-(

This situation arrises mostly when I try to exit the program. Then I want to make the working thread stop at any time, and once it is done, I can safely proceed to destroy my main window. However, waiting for thread termination (through WaitForSingleObject) happens (way too) often when the working thread is in the SendMessage situation, and my program deadlocks...

Does anyone know of a way to make the PostMessage messages be read in FIFO order? Or any clever ideas on how to avoid my deadlocks using SendMessage?

Thanks,

Vincent
 
Try to use SendMessageTimeout(... ) - it can avoid deadlocks and lets right order.
 
Thanks tchouch! I figured that was probably what I needed, but somehow failed to see it in the MSDN index... The heat must have baked my brains for good! %-)

Vincent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top