title: Updating multiple properties asynchronously in a list
body: <p>I am creating an ObservableCollection of ViewModel objects, where each object has several tasks to complete when it gets initialized.</p>
  
  <p>I'm adding these to an ObservableCollection like this in the parent viewmodel:</p>
  
  <pre><code>public async void ButtonPressCommandHandler() 
  {
      for (int i = 0; i &lt; 25; ++i)
      {
          var testViewModel = new TestViewModel();
          await testViewModel.Initialize();
          TestViewModels.Add(testViewModel);
      }
  }
  </code></pre>
  
  <p>That loop just gets called on a button click or some other event.</p>
  
  <p>And here's the test viewmodel code:</p>
  
  <pre><code>public class TestViewModel : ViewModelBase
  {
      private string _taskOne;
      public string TaskOne
      {
          [DebuggerStepThrough]
          get { return _taskOne; }
          set
          {
              if (value != _taskOne)
              {
                  _taskOne = value;
                  RaisePropertyChanged(() =&gt; TaskOne);
              }
          }
      }
  
      private string _taskTwo;
      public string TaskTwo
      {
          [DebuggerStepThrough]
          get { return _taskTwo; }
          set
          {
              if (value != _taskTwo)
              {
                  _taskTwo = value;
                  RaisePropertyChanged(() =&gt; TaskTwo);
              }
          }
      }
  
      public async Task Initialize()
      {
          TaskOne = await TaskOneAsync();
          TaskTwo = await TaskTwoAsync();
      }
  
      private Task&lt;string&gt; TaskOneAsync()
      {
          return Task.Factory.StartNew(() =&gt;
          {
              Thread.Sleep(100);
              return "Task one";
          });
      }
  
      private Task&lt;string&gt; TaskTwoAsync()
      {
          return Task.Factory.StartNew(() =&gt;
          {
          var random = new Random();
          int randomNumber = random.Next(500, 5000);
          Thread.Sleep(randomNumber);
          return "Task two: " + randomNumber;
              Thread.Sleep(randomNumber);
              return "Task two: " + randomNumber;
          });
      }
  }
  </code></pre>
  
  <p>(I know I can call the init work in the constructor, but this is closer to what I really need to do.)</p>
  
  <p>In my view, I have a <code>ListView</code> where the <code>ListView.ItemTemplate</code> just displays text blocks with the <code>TaskOne</code> and <code>TaskTwo</code> properties.  It's <code>ItemSource</code> is bound to <code>TestViewModels</code>.</p>
  
  <p>What I see is that for each of the 25 objects created, <code>TaskOne</code> and <code>TaskTwo</code> properties both appear at the same time, and each object shows only after both tasks have completed.</p>
  
  <p>If I remove the <code>await</code> from <code>Initialize()</code> and have <code>Initialize()</code> return void (this IS on the UI thread) the behavior is better- I see all <code>TaskOne</code> properties very quickly, and then the <code>TaskTwo</code> properties start to fill in.  But the random values they display are wrong- there are many duplicates and they appear to fill in the list in chunks or 4 or 5 (kind of hard to say).  </p>
  
  <p>The whole goal of this in non-test code is to update a progress indicator tied to <code>TaskTwo</code>.  Something like this (from the <code>TestViewModel</code> code):</p>
  
  <pre><code>public async Task Initialize()
  {
      TaskOne = await TaskOneAsync();
      Loading = true;
      TaskTwo = await TaskTwoAsync();
      Loading = false;
  }
  </code></pre>
  
  <p>Where all the objects load immediately into the list, and then asynchronously update their <code>TaskOne</code>  and <code>TaskTwo</code> properties as they complete, and update the progress indicator based off of the work in <code>TaskTwo</code>.  But so far no luck in getting this to work.</p>
  
  <p>EDIT:  Added better example code and explanations</p>