Message pump




  • Dapfor Team


    Let us assume that the computer resources are not limitless. Theoretically the maximum performance can be obtained if the number of threads equals to the number of processor cores. While a lot of threads are creating, they aren’t working in parallel. In this case cores allocate time slices to threads based on their priority and consistently perform context switches (context switch is relatively expansive operation). Note, maximum time slice is about 10-15 msec.

    You have also take into account that each control paints its content in the GDI/GDI+ device (via the Graphics object). While painting from one thread all others wait for GDI device to perform painting in its turn. Therefore if you start many message loops – it doesn’t mean that you accelerate the application. In other words the application losses time on context switches and on drawing in GDI device.

    From our point of view the application should have only one message pump. Windows has additional mechanisms that optimize content drawing and we are not sure that they work in case of multithreaded environment. Of course, your business logic can work in any thread, but the graphical thread should be only one in the application.

    Best regards,

  • guest

    Thanks for the answer. I changed the code to not use a message pump per form and limiting the amount of threads. It now works as expected.

  • Dapfor Team


    If you have any questions - don't hesitate ask us.

    Best regards,

Please sign in to leave a comment.

Powered by Zendesk