I came across the Dispatcher class's PushFrame method. I quickly looked at the implementation and read about it in the documentation. Here is a simplified version of this method.

 public void PushFrame(DispatcherFrame frame) { // Stuff _frameDepth++; while(frame.Continue) { // Getting and dispatching messages } _frameDepth--; // Stuff } 

I understand that the method simply creates and processes a new message loop. But I can not understand what goals such an approach can achieve? Is not one cycle enough? Moreover, I am very confident that using another nested loop can lead to rather unobvious errors.

    1 answer 1

    Good question.

    In short - you should not use it in the usual case, this method is the internal method of the infrastructure.

    Situations in which it would be necessary to use PushFrame - blocking methods like ShowDialog (in ShowDialog itself PushFrame is also used ). In them, you need to stop the processing of the message cycle for the duration of the blocking function, and for PushFrame , a nested cycle is created using PushFrame .

    In modern C #, the use of blocking methods is considered non-idiomatic. The correct design from the standpoint of today would be the use of an async variant. Here are examples of such a design with code.

    • Yes indeed. For modal windows it’s the most - LmTinyToon