Thread
-
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
-
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
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++ -
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++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
-
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
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++ -
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
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
-
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++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 !