336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

PostMessage , SendMessage 쓰레드간 메시지 주고받을때, 동기화


PostMessage (in "pure windows programming", aka win32 API) is asynchronous, i.e., to quote the docs:

Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.

To post a message in the message queue associated with a thread, use the PostThreadMessage function.

SendMessage is synchronous, that is, again quoting:

Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.

To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.

A good tutorial on these two functions and their use is here.

The connection to WPF is discussed in this SO question.



PostMessage 는 메세지 큐에만 넣어주고 메세지 처리 까지는 기다리지 않기 때문에 비동기 처리, 보낸 순서와 메세지 처리 끝나는 시점이 순서가 맞지 않을 수 있다.



SnedMessage 는 메세지 큐에만 넣어주고 메세지 처리 까지 기다리기 때문에 동기 처리, 하나의 메세지가 다 처리되고나서 다음 메세지가 처리된다.