title: Can't await task on MainWindow Loaded event
body: <p>I can't await my task when i load window. I have three <code>viewmodel</code>, with three <code>initialize</code>, and this three initialize have 1 async method to return data from database, and 1 synchronous method. If i try load this data i have exception (<code>ViewModel return null</code>) or my load animation (binded to property) set hidden.</p>
  
  <p>TLDR: <code>Window.Load</code> don't wait when task is complete (like synchronus method been in this task), and fire next.</p>
  
  <p>I search for answer in google, and stack but nothing work for me and CogAnim set False before.</p>
  
  <p>I try doing this in <code>Task.Factory</code> like this</p>
  
  <pre><code>    public MainWindow()
      {
          CogAnim = true;
          InitializeComponent();
          DataContext = this;
          Loaded += MainWindow_Loaded;
      }
  
      public bool CogAnim { get; set; }
  
      private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
      {
          var t = await Task.Factory.StartNew(async () =&gt;
          {
              await Task.Run(() =&gt; ViewModelOne = new ViewModelOne());
              await Task.Run(() =&gt; ViewModelTwo = new ViewModelTwo());
              await Task.Run(() =&gt; ViewModelThree = new ViewModelThree());
          }).ContinueWith((t1) =&gt; ViewModelOne.Initialize()).ContinueWith((t2) =&gt; ViewModelTwo.Initialize()).ContinueWith((t3) =&gt; ViewModelThree.Initialize());
          t.Wait();
          CogAnim = false;
          OnPropertyChanged("CogAnim");
      }
  </code></pre>
  
  <p>And try without this <code>await Task.Run(() =&gt; {modelname})</code>.</p>
  
  <p>How properly create ViewModels, and use Initialize in it without freeze window?
  Only work when i do it like this but this freeze gui and load animation dont work</p>
  
  <pre><code>private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
  {
      ViewModelOne = new ViewModelOne();
      ViewModelTwo = new ViewModelTwo();
      ViewModelThree = new ViewModelThree();
      await ViewModelOne.Initialize();
      await ViewModelTwo.Initialize();
      await ViewModelThree.Initialize();
      CogAnim = false;
      OnPropertyChanged("CogAnim");
  }
  </code></pre>
  
  <p>This <code>Initialize</code> method look like this (maybe there is problem):</p>
  
  <pre><code>public async Task Initialize()
  {
      await Task.Delay(2000);
      var t = Repo.GetOne();
      foreach(var a in t)
      {
          CollectionOne.Add(a);
      }
  
      await Select();
  }
  public async Task Select()
  {
      var t = await Repo.GetOneAsync();
      foreach(var a in t)
      {
          CollectionOne.Add(a);
      }
  }
  </code></pre>