Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. PostMessage or SendMessage from thread?

PostMessage or SendMessage from thread?

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gilfrog
    wrote on last edited by
    #1

    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

    R V 2 Replies Last reply
    0
    • G Gilfrog

      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

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      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

      G 1 Reply Last reply
      0
      • R Ravi Bhavnani

        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

        G Offline
        G Offline
        Gilfrog
        wrote on last edited by
        #3

        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?

        M 1 Reply Last reply
        0
        • G Gilfrog

          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?

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          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 function AtlWaitWithMessageLoop() 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

          G 1 Reply Last reply
          0
          • M Michael Dunn

            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 function AtlWaitWithMessageLoop() 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

            G Offline
            G Offline
            Gilfrog
            wrote on last edited by
            #5

            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

            M 1 Reply Last reply
            0
            • G Gilfrog

              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

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • G Gilfrog

                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

                V Offline
                V Offline
                valikac
                wrote on last edited by
                #7

                I use SendMessage() to update the main thread of new changes. However I use PostMessage() right before returning from the thread so the main thread can close the thread. Kuphryn

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups