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. Thread

Thread

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasetutorialquestion
6 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.
  • S Offline
    S Offline
    shakumar_22
    wrote on last edited by
    #1

    Hi In my apllication vc++ 6.0 i have 2 thread’s running ThraedA and ThreadB. In ThreadB some process is keep going. In ThreadA ,there is a button on clicking, it should send a message to ThreadB(which is busy on doing some other task). Now my query is this, when ThreadA send a message to ThreadB ,ThreadB should immediately display the Received Message . how to do this ? regards shakumar

    shakumar

    C D 2 Replies Last reply
    0
    • S shakumar_22

      Hi In my apllication vc++ 6.0 i have 2 thread’s running ThraedA and ThreadB. In ThreadB some process is keep going. In ThreadA ,there is a button on clicking, it should send a message to ThreadB(which is busy on doing some other task). Now my query is this, when ThreadA send a message to ThreadB ,ThreadB should immediately display the Received Message . how to do this ? regards shakumar

      shakumar

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Normally, a thread can't receive a message if it is a working thread. If it is a UI thread, then it can have a message loop and extract messages from its queue. Of course, it can only retrieve messages when it tries to do so and if it is busy doing something else, then you can't extract the message. Typically, it is not really done this way: you set a flag (e.g. a boolean) in one thread which can be checked in the second thread. What are you trying to do in fact ? Some context could be usefull to help you.

      Cédric Moonen Software developer
      Charting control [v1.4] OpenGL game tutorial in C++

      S 1 Reply Last reply
      0
      • C Cedric Moonen

        Normally, a thread can't receive a message if it is a working thread. If it is a UI thread, then it can have a message loop and extract messages from its queue. Of course, it can only retrieve messages when it tries to do so and if it is busy doing something else, then you can't extract the message. Typically, it is not really done this way: you set a flag (e.g. a boolean) in one thread which can be checked in the second thread. What are you trying to do in fact ? Some context could be usefull to help you.

        Cédric Moonen Software developer
        Charting control [v1.4] OpenGL game tutorial in C++

        S Offline
        S Offline
        shakumar_22
        wrote on last edited by
        #3

        thanks for reply As I mentioned above it is an UI Thread only. My query is , I able to post a message to ThreadB , from ThraedA. When ThreadB was free it receive the message and displayed it. When ThreadB was doing some process ,it is not displaying the received message . After completing the ThreadB process only it display this received message. I want ThreadB to display the Message immediately, when message was posted from ThreadA. regards shakumar

        shakumar

        C 1 Reply Last reply
        0
        • S shakumar_22

          thanks for reply As I mentioned above it is an UI Thread only. My query is , I able to post a message to ThreadB , from ThraedA. When ThreadB was free it receive the message and displayed it. When ThreadB was doing some process ,it is not displaying the received message . After completing the ThreadB process only it display this received message. I want ThreadB to display the Message immediately, when message was posted from ThreadA. regards shakumar

          shakumar

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          As I explained in my previous post, this is not possible unless, you pump your message loop. This is done for example when you give back control to the MFC lib (when your function exits). It's still one thread so when you are busy in your function, nothing else will be processed for that thread. Ok, but I also asked you a question: what are you trying to do exactly ? Give some context, it might help. What are you doing in that function that takes so much time ? Anyway, it is also not a good idea to have lenghty function call in a UI thread, because your UI will be freezed during that time.

          Cédric Moonen Software developer
          Charting control [v1.4] OpenGL game tutorial in C++

          S 1 Reply Last reply
          0
          • S shakumar_22

            Hi In my apllication vc++ 6.0 i have 2 thread’s running ThraedA and ThreadB. In ThreadB some process is keep going. In ThreadA ,there is a button on clicking, it should send a message to ThreadB(which is busy on doing some other task). Now my query is this, when ThreadA send a message to ThreadB ,ThreadB should immediately display the Received Message . how to do this ? regards shakumar

            shakumar

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            shakumar_22 wrote:

            ...ThreadB should immediately display the Received Message .

            How (e.g., message box, console, debug window)?

            "Love people and use things, not love things and use people." - Unknown

            "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

            1 Reply Last reply
            0
            • C Cedric Moonen

              As I explained in my previous post, this is not possible unless, you pump your message loop. This is done for example when you give back control to the MFC lib (when your function exits). It's still one thread so when you are busy in your function, nothing else will be processed for that thread. Ok, but I also asked you a question: what are you trying to do exactly ? Give some context, it might help. What are you doing in that function that takes so much time ? Anyway, it is also not a good idea to have lenghty function call in a UI thread, because your UI will be freezed during that time.

              Cédric Moonen Software developer
              Charting control [v1.4] OpenGL game tutorial in C++

              S Offline
              S Offline
              shaibee
              wrote on last edited by
              #6

              As Cedric said, you need to pump your messages, while you are busy doing something else. This means you need to add a message loop to your class , and call the loop several times while you are through a long process, to let all the awaiting messages come up. Something like MSG msg; while (PeekMessage(&msg ...)) { TranslateMessage(&msg); DispatchMessage(msg); }

              Its never over !

              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