Need help locking the Dispatcher.PushFrame style process on a WPF page

I use Dispatcher.PushFrame to lock my code, allowing the user interface to be updated until a lengthy process is completed. This works as expected, as long as my Dispatcher.PushFrame call comes from a button click event. If, however, I use the same code during an event or Pages Loaded constructor, the user interface is not updated, and therefore it is never painted. As a random experiment, I tried to use Window.ShowDialog from the constructor, and it allows the graphics editor to draw, although control is blocked until the modal dialog is closed. Can anyone suggest a solution that allows you to use this function from a page loading event using Dispatcher.PushFrame or some other manual mechanism?

In addition, if I minimize or maximize my window, the user interface draws, and I can interact normally with it, but only until I manually resize it.

+6
wpf
source share
1 answer

From my testimony on MSDN on Life-Span Events and overflows in Reflector, it seems that Loaded and Unloaded events are not raised in the same way as other events. Inside, the BroadcastEventHelper class is used, which coordinates the various Loaded events among each element in the visual tree, before ultimately raising them at the DispatcherPriority.Loaded level.

I believe that is why you see this behavior.

As for the specific solution, I suggest that long tasks not be placed in the Page.Loaded event Page.Loaded , and instead a BackgroundWorker or Task is issued to complete the job.

+3
source share

All Articles