Good day!

I am engaged in the development of controls in the system. This control is something like "ms visio" schemes. Not long ago I learned that some use a separate stream for drawing. In principle, it’s not causing me to draw in the flow of questions, but it seems to me rather cumbersome exercise for such schemes to synchronize user actions (selecting blocks, removing blocks, editing, changing states, etc.).

By cumbersome, I understand that there are quite a lot of different objects and states in the circuit that should be safely changed and everything should be smooth without brakes.

Question: Does it make sense to render the drawing in a separate stream for such schemes as in ms visio and if so, what are the basic principles of synchronization in such an architecture?

    1 answer 1

    Since the question does not mention any particular framework, there is no predefined behavior. Some frameworks themselves draw for you in the background, some draw synchronously.

    If you want to do your own rendering in the background thread, I would do this:

    1. The code that works with UI components has the illusion of single-threading. That is, no blocking is needed.
    2. When changes are made, the controls should send the notification to the stream that deals with the drawing. The notification should contain all the data necessary for the drawing, so that the drawing stream should not have to contact the main flow for information.

    At the same time, the state of the UI will lag a little behind the “true” state of affairs, but with sufficient rendering speed this will be imperceptible.


    About whether it makes sense to do so - you have to experiment. Unfortunately, it is very difficult to say in advance what the effect of this or that technique will be, and is it not easier to simply purchase the equipment (a good graphics card) and take advantage of its capabilities. Write two prototypes and run them on typical tasks for your program.

    • Regarding paragraph 2: I understand correctly that in this interaction it is necessary that the second thread have a copy of its objects and states? - Vasek
    • @Vasek: Not necessary. You can not give a complete copy of the object, but only the information necessary for drawing. Moreover, the second stream, according to the idea, may not cache this information: the definition of the exact area of ​​the redrawing can be done in the main stream, and for the other objects, it seems, they are not needed. - VladD
    • And if you need to redraw the whole scene? for example when scrolling. - Vasek
    • Perhaps, then it makes sense to the scrolling code not to let the elements of the list send notifications, but send the most one, cumulative notification itself? - VladD
    • figured it out, thanks - Vasek