asynchronousinitializecomponent

InitializeComponent asynchrounously


Is it possible to make asynchronous InitializeComponent? Otherwise could I load my WPF component asynchronously? More specifically I'm currently developping a product in WPF and I noticed that the loading time of graphical components (some components) is quite big when I have performance requirements.


Solution

  • If you create a component on the UI thread so there's no way to put InitializeComponent on another thread, but it can be called asynchronously in the same thread using Dispatcher.BeginInvoke as follows:

    Dispatcher.BeginInvoke(new Action(() =>InitializeComponent()));