0

I'm using MVVM ViewModel first with Stylet. I have a method that takes a long time to run called Run in my Simulation class and I want to open window with a status bar which has a viewModel called StatusViewModel.

The result I am getting is a blank window opens, the method Run runs, and only when this method has finished does the content of the window display the Status Bar.

How do I get the method Run to only run once the view of the status bar window is loaded?

I am currently opening the status widow and running the Run method as follows:

public void RunSimulation()
    {
        this.windowManager.ShowWindow(StatusViewModel);
        simulations.Run(StatusViewModel);
    }

I've also tried the following in the StatusViewModel but I get the same result:

protected override void OnViewLoaded()
    {
        simulations.Run(this);
    }

I feel that I need a protected override that only fires once the view has finished loading, rather than load being called as it does with OnViewLoaded.

What other ways are there to achieve what I want?

Richard
  • 439
  • 3
  • 25
  • What you need is to run the `Run` method asynchronously : https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/ – Orace Mar 07 '22 at 11:17
  • I've got that working as intended now, many thanks – Richard Mar 07 '22 at 12:19

0 Answers0