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. User Interface Thread Problem !

User Interface Thread Problem !

Scheduled Pinned Locked Moved C / C++ / MFC
helpdesignquestion
7 Posts 5 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.
  • M Offline
    M Offline
    M Mehrdad M
    wrote on last edited by
    #1

    I Created an User Interface Thread and Activated that, with AfxBeginThread(), Ineed to post a message To thread immediately after creation, But MessageLoop Not Work at that time. one millisecond Sleep() can Solve The Problem But In My App Not Acceptable. :confused: Any Idea,Suggestion,Help? Thanks a lot. M.Mehrdad.M

    J D M 3 Replies Last reply
    0
    • M M Mehrdad M

      I Created an User Interface Thread and Activated that, with AfxBeginThread(), Ineed to post a message To thread immediately after creation, But MessageLoop Not Work at that time. one millisecond Sleep() can Solve The Problem But In My App Not Acceptable. :confused: Any Idea,Suggestion,Help? Thanks a lot. M.Mehrdad.M

      J Offline
      J Offline
      Jun Du
      wrote on last edited by
      #2

      You are right in that after you called AfxBeginThread(), you cannot tell when the thread is actually up and running. A normal approach is to make your UI thread to notify the main thread at the very beginning of the thread function, presumably before the thread loop.

      Best, Jun

      1 Reply Last reply
      0
      • M M Mehrdad M

        I Created an User Interface Thread and Activated that, with AfxBeginThread(), Ineed to post a message To thread immediately after creation, But MessageLoop Not Work at that time. one millisecond Sleep() can Solve The Problem But In My App Not Acceptable. :confused: Any Idea,Suggestion,Help? Thanks a lot. M.Mehrdad.M

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

        M.Mehrdad.M wrote:

        Ineed to post a message To thread...

        Which thread? :confused: Which one is sending and which one is receiving?


        "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

        "Judge not by the eye but by the heart." - Native American Proverb

        M 1 Reply Last reply
        0
        • M M Mehrdad M

          I Created an User Interface Thread and Activated that, with AfxBeginThread(), Ineed to post a message To thread immediately after creation, But MessageLoop Not Work at that time. one millisecond Sleep() can Solve The Problem But In My App Not Acceptable. :confused: Any Idea,Suggestion,Help? Thanks a lot. M.Mehrdad.M

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

          The main thread needs to wait until the second thread's message queue is ready. The steps go like this: 1. Main thread creates an event object that the second thread will be able to access 2. Main thread creates the second thread 3. Main thread waits on the event, so it will block 4. Second thread calls PeekMessage() during its initialization to create a message queue for itself 5. Second thread signals the event 6. Main thread wakes up and now the second thread's message queue is available to receive messages

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          M 1 Reply Last reply
          0
          • D David Crow

            M.Mehrdad.M wrote:

            Ineed to post a message To thread...

            Which thread? :confused: Which one is sending and which one is receiving?


            "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

            "Judge not by the eye but by the heart." - Native American Proverb

            M Offline
            M Offline
            M Mehrdad M
            wrote on last edited by
            #5

            DavidCrow wrote:

            Which one is sending and which one is receiving?

            newly created thread must get a message in it's message que.

            1 Reply Last reply
            0
            • M Michael Dunn

              The main thread needs to wait until the second thread's message queue is ready. The steps go like this: 1. Main thread creates an event object that the second thread will be able to access 2. Main thread creates the second thread 3. Main thread waits on the event, so it will block 4. Second thread calls PeekMessage() during its initialization to create a message queue for itself 5. Second thread signals the event 6. Main thread wakes up and now the second thread's message queue is available to receive messages

              --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

              M Offline
              M Offline
              M Mehrdad M
              wrote on last edited by
              #6

              thanks a lot Mike,

              Michael Dunn wrote:

              5. Second thread signals the event

              I had same idea, too. but the problem is when newly created thread must set that Event with best regareds, M.Mehrdad.M

              B 1 Reply Last reply
              0
              • M M Mehrdad M

                thanks a lot Mike,

                Michael Dunn wrote:

                5. Second thread signals the event

                I had same idea, too. but the problem is when newly created thread must set that Event with best regareds, M.Mehrdad.M

                B Offline
                B Offline
                Blake Miller
                wrote on last edited by
                #7

                The original thread creates the event. The second thread OPENS the event, and can signal it just fine. Otherwise, the secondary thread can receive the handle to the event too, if you wanted. It should have no problem signaling the event, whether or not it has a message queue.

                Any sufficiently gross incompetence is nearly indistinguishable from malice.

                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