Solved

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

Posted on 1998-07-02
4
670 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
substring method in java 1 118
difference between String.subString() and String.subSequence() 6 194
wordappend challenge 8 172
"Black Box" Testing of Control System Software 2 49
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 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