title: Portable Class Library and ObservableCollection, updating UI Thread
body: <p>I'm not very experienced with this topic so forgive me if this isn't very clear.</p>
  
  <p>I've created a Portable Class Library that has an ObservableCollection of Sections, and each secion has an ObservableCollection of Items.</p>
  
  <p>Both of these collections are bound to the UI of separate Win8 and WP8 apps.</p>
  
  <p>I'm trying to figure out the correct way to populate these collections correctly so that the UI gets updated from the PCL class.</p>
  
  <p>If the class was inside the win8 project I know I could do something like Dispatcher.BeginInvoke, but this doesn't translate to the PCL, nor would I be able to reuse that in the WP8 project.</p>
  
  <p>In this thread (<a href="https://stackoverflow.com/questions/11258164/portable-class-library-equivalent-of-dispatcher-invoke-or-dispatcher-runasync">Portable class library equivalent of Dispatcher.Invoke or Dispatcher.RunAsync</a>) I discovered the SynchroniationContext class.</p>
  
  <p>I passed in a reference to the main app's SynchroniationContext, and when I populate the sections I can do so because it's only the one object being updated:</p>
  
  <pre><code>if (SynchronizationContext.Current == _synchronizationContext)
  {
      // Execute the CollectionChanged event on the current thread
      UpdateSections(sections);
  }
  else
  {
      // Post the CollectionChanged event on the creator thread
      _synchronizationContext.Post(UpdateSections, sections);
  }
  </code></pre>
  
  <p>However, when I try to do the same thing with articles, I have to have a reference to both the section AND the article, but the Post method only allows me to pass in a single object.</p>
  
  <p>I attempted to use a lambda expression:</p>
  
  <pre><code>if (SynchronizationContext.Current == _synchronizationContext)
      {
  // Execute the CollectionChanged event on the current thread
      section.Items.Add(item);
  }
  else
  {
      // Post the CollectionChanged event on the creator thread
      _synchronizationContext.Post((e) =&gt;
      {
          section.Items.Add(item);
      }, null);
  }
  </code></pre>
  
  <p>but I'm guessing this is not correct as I'm getting an error about being "marshalled for a different thread".</p>
  
  <p>So where am I going wrong here? how can I update both collections correctly from the PCL so that both apps can also update their UI?</p>
  
  <p>many thanks!</p>