Message pump
FeaturedI have a requirement to open a lot of forms concurrently (+- 50). Each form contains a grid doing realtime updates (market data). The problem I see is that it does perform well with 10 forms but when opening 50 painting becomes very slow. It's almost as if the grids share a message pump. I'm opening the forms in threads so I thought each form would have it's own message pump.
Any idea what's going on?
-
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,
Dapfor0 -
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 -
Great!
If you have any questions - don't hesitate ask us.
Best regards,
Dapfor0
Please sign in to leave a comment.
Comments
3 comments