Solved

<=== >  Message Pump  <===>

Posted on 1998-07-02
4
663 Views
Last Modified: 2013-11-19
if a worker thread is derived from CWinThread using AfxBeginThread why does it not have a message pump ???
0
Comment
Question by:pcj0961
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 50 total points
ID: 1318664
There are tow kind of of thread, UI thread and worker thread. UI thread contains message pump and in MFC usually derived from CWinThread. Worker thread is usually thread function so when this function returns worker thread terminates. Thre are two overloaded version of AfxBeginThread. When you create UI thread you cpesify pointer to CWinThread class. This class has Run virtual function that contains message pump. The second version of AfxBeinThread is passed pointer to worker thread entry function.
0
 
LVL 1

Author Comment

by:pcj0961
ID: 1318665
I have created a worker thread using AfxBeginThread
that has a for(;;){} loop that never returns (it runs continuosly looking for messages passed to it). Is it better
to do this type of application (thread) with a UI thread and use the Run(){} loop of the CWinThread object to do my processing.
0
 
LVL 7

Expert Comment

by:galkin
ID: 1318666
Worker thread doesn't have any windows so it is impossible to send message to it. Usually worker thread does some data processing and notifies main UI thread using messages. If you still want your worker thread to have a window, create hidden window inside CWinThread::InitInstance and assign it's pointer to m_pMainWnd. then you can send messages to this hidden window.
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1318667
Any thread can have a message pump! But if the thread do not create any windows or do not need to receive messages posted using PostThreadMessage() there is no reason to do a message pump.

Remember: Windows are owned by the thread that created them.


0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 98
sum13 challenge 24 77
sum28 challenge 31 95
either24  challenge 19 84
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now