UI thread function 
Author Message
 UI thread function

I read here that UI threads are nothing but threads with
message pumps, so I decided to use them in my application,
instead of worker threads, so that I can post messages to
them.

I am using CWinThread derived class. This class has
InitInstance() and ExitInstance(), but which is the thread
function? Where will I put my thread code? Do I have to
override "Run" member function? (I read that "Run" is very
rarely overridden.)



Wed, 14 Sep 2005 11:03:43 GMT  
 UI thread function

Quote:

> I read here that UI threads are nothing but threads with
> message pumps, so I decided to use them in my application,
> instead of worker threads, so that I can post messages to
> them.

> I am using CWinThread derived class. This class has
> InitInstance() and ExitInstance(), but which is the thread
> function? Where will I put my thread code? Do I have to
> override "Run" member function? (I read that "Run" is very
> rarely overridden.)

If you used the wizard to create your CWinThread-derived class then your
class has a message map.  Add a line like this into it for every message
that you want to handle:

 ON_THREAD_MESSAGE(UWM_SHUTDOWN, OnShutdownMsg)

When the UWM_SHUTDOWN message comes in your function will be called:

void CCommoThread::OnShutdownMsg(UINT, LONG)
{
...

Quote:
}

The "Run" function is your thread's message loop and works with the
message map to dispatch messages.  If you want the thread to be entirely
message-driven then there is no need to overrride "Run".

--
Scott McPhillips [VC++ MVP]



Wed, 14 Sep 2005 14:53:58 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Starting a UI Thread from a UI Thread.

2. Doubt in dialog based threads in linux (UI threading)

3. MFC UI Thread doesnt start when COM method called in multi-threaded MFC dialog App

4. Doubt in dialog based threads in linux (UI threading)

5. UI Thread better than Worker thread for speed?

6. Awakening the UI thread from another thread in a Windows Form application

7. worker thread to ui thread

8. Is it possible for one (UI) thread to Peek into another (UI) threads message queue ?

9. Threads and UI controls

10. Threads and the UI

11. Multi-Threaded UI problem involving Asynch Sockets

12. UI thread and activex control

 

 
Powered by phpBB® Forum Software