You need to create a VM in a separate thread. I tried two options:
This option inhibits the main thread.
public class MainVm : VmBase { public ButtonsVm ButtonsVm { get; private set; } public MainVm() { Init(); } private async void Init() { var uiContext = TaskScheduler.FromCurrentSynchronizationContext(); ButtonsVm = await Task.Factory.StartNew(() => new ButtonsVm(), CancellationToken.None, TaskCreationOptions.None, uiContext); } }With this flies exception
public class MainVm : VmBase { public ButtonsVm ButtonsVm { get; private set; } public MainVm() { Init(); } private async void Init() { await Task.Run(() => ButtonsVm = new ButtonsVm()); } }
Additional information: Must create Dependency Source on the Thread as the DependencyObject.
UPDATE: ButtonsVm contains about 15 VMs in itself, and refers to the model that works with Entity, so I want to bring its creation to a separate thread so that the first connection to the database does not slow down the program.