title: Async and populating data for WPF application
body: <p>I have a WPF application that initializes the state of the UI via methods in the constructor. However, it's never returning from the <code>Wait();</code> in the constructor.</p>
  
  <p>Here's what I am currently doing via a fairly-contrived sample:</p>
  
  <pre><code>public class SomeViewModel
  {
      public ICommand AddDataCommand { get { return RelayCommand(AddDataExecute); } }
      public ObservableCollection&lt;int&gt; UIData { /* Property with INotifyPropertyChanged */}   
  
      public SomeViewModel() 
      {
          //Load synch. here
          LoadData().Wait();      
      }
  
      public async Task LoadData()
      {
          UIData = await Task.Run(() =&gt; SomeService.SelectAllUIData());
      }
  
      public async void AddDataExecute()
      {
          //Add new data item to database on separate thread to keep UI responsive
          await Task.Run(() =&gt; SomeService.AddNewData(0));
  
          //Reload data from database and update UI, has to happen after AddNewData completes
          await LoadData();
      }
  }
  </code></pre>
  
  <p>I believe it's hanging because I am never actually returning a <code>Task</code>. However, I don't know of a different way to assign UIData asynchronously that works both in the constructor and the Commands that call it.</p>