Threading 101: What is a dispatcher?

Once I remembered it by heart. Over time, my understanding has blurred, and I want to refresh it.

As I recall, any so-called single-threaded application has two threads:

a) the main stream, which has a pointer to the main or DllMain entry points; and

b) For applications that have some UI, a user interface thread, aka a secondary thread that runs WndProc, that is, a thread that runs WndProc, which receives messages that Windows sends to it. In short, a thread that runs a Windows message loop.

For user interface applications, the main thread is in a blocking state, waiting for messages from Windows. When he receives them, he queues them and sends them to the message loop (WndProc), and the user interface thread starts.

As I understand it, the main thread in a blocking state is this:

C ++

while(getmessage(/* args &msg, etc. */))
{
    translatemessage(&msg, 0, 0);
    dispatchmessage(&msg, 0, 0);
}

C # or VB.NET WinForms Applications:

Application.Run( new System.Windows.Forms() );

Is this what they call a dispatcher?

My questions:

a) Is this my understanding?

b) What goes into hell - Dispatcher?

c) Call me to a resource where I can better understand threads from a Windows / Win32 perspective, and then bind it to high-level languages ​​like C #. Petzold spares in his discussion of this issue in his epic work.

Although I believe that this is somewhat correct with me, confirmation will be facilitated.

+5
1

, . , , . , . , .

(, ) ( , ). . , . , , ..

Edit:

:

class Event{
   public:
   EventType type; //Probably an enum
   String data; //Event data
};

class Dispatcher{
   public:
   ...

   dispatch(Event event)
   {
      switch(event.type)
      {
         case FooEvent:
            foo(event.data);
            break;
            ...
       }
   };

, , "", , . , , . , , .

+1

All Articles