User Interface Thread Problem !
-
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
-
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
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
-
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.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
-
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
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.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
DavidCrow wrote:
Which one is sending and which one is receiving?
newly created thread must get a message in it's message que.
-
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
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
-
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
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.