Skip to main content

Message pump

Featured

Comments

3 comments

  • Dapfor Team

    Hello,

    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,
    Dapfor

    0
  • 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.

    0
  • Dapfor Team

    Great!

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

    Best regards,
    Dapfor

    0

Please sign in to leave a comment.

Powered by Zendesk