PostMessage or SendMessage from thread?
-
Should i use a postmessage or a sendmessage in a thread to send information back to my dialog. I need the messages to get there in the order i sent them, does postmessage do this all the time? thanks Scott
Both will get the message to your window.
SendMessage
will block your thread,PostMessage
won't. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com -
Both will get the message to your window.
SendMessage
will block your thread,PostMessage
won't. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.comYa the problem I am having is when exiting the app, i want to exit the thread. If i use send message and on exit I WaitForSingleObject(hHandle, INFINTE) then it freezes the main program and never lets the thread back to end. I could use send message but I'm not sure if i want to or not. Is there a better way of ending threads?
-
Ya the problem I am having is when exiting the app, i want to exit the thread. If i use send message and on exit I WaitForSingleObject(hHandle, INFINTE) then it freezes the main program and never lets the thread back to end. I could use send message but I'm not sure if i want to or not. Is there a better way of ending threads?
If I understand, your main thread is blocked waiting for the second thread to exit, but you also want the second thread to send a message to the dialog right before it exits? You should use
MsgWaitForMultipleObjects()
which will return if a message appears in the queue. ATL has a handy functionAtlWaitWithMessageLoop()
as well. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm -
If I understand, your main thread is blocked waiting for the second thread to exit, but you also want the second thread to send a message to the dialog right before it exits? You should use
MsgWaitForMultipleObjects()
which will return if a message appears in the queue. ATL has a handy functionAtlWaitWithMessageLoop()
as well. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_HelmWhat the thead does is do some file reads and some calculating and then sends the inforation back to the main program to be put in a list box. So on exit of the app say MsgWaitForMultipleObjects() wich will allow the message that the thead sent to continue but wait the main program to exit until hHandle has been set that i'm waiting on? Scott
-
What the thead does is do some file reads and some calculating and then sends the inforation back to the main program to be put in a list box. So on exit of the app say MsgWaitForMultipleObjects() wich will allow the message that the thead sent to continue but wait the main program to exit until hHandle has been set that i'm waiting on? Scott
MsgWaitForMultipleObjects() will unblock when either the handle is signaled, or a message is put in the queue. So you'd loop while the return value is WAIT_OBJECT_0+1. If that's returned, a message was posted, so call GetMessage/TranslateMessage/DispatchMessage to process it, then wait again. When the return value is WAIT_OBJECT_0, the handle is signaled (meaning the thread has exited). --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
Should i use a postmessage or a sendmessage in a thread to send information back to my dialog. I need the messages to get there in the order i sent them, does postmessage do this all the time? thanks Scott