title: C# / WPF Databinding and backgroundworkers
body: <p><strong>Update2</strong></p>
  
  <p><em>I've rewritten the entire question, because some things became a lot clearer, the issue now seems to be that I created a list of DependencyProperties on a different thread than where the DependencyProperties will be used :(.</em></p>
  
  <p>When I do some work on a <code>BackgroundWorker</code> the <code>XAML</code> bindings cause an <code>ArgumentException</code></p>
  
  <blockquote>
    <blockquote>
      <p>Must create DependencySource on same Thread as the DependencyObject.</p>
    </blockquote>
  </blockquote>
  
  <p>I've got the following setup:</p>
  
  <p>I've got a simple class that implements  <code>INotifyPropertyChanged</code> which contains a few ints, list's and Dictionaries.</p>
  
  <pre><code>public class Calculator : INotifyPropertyChanged
  {
      //Note that InstanceGroup is a dependency object
      private List&lt;InstanceGroup&gt; instanceGroups = new List&lt;InstanceGroup&gt;();
      public List&lt;InstanceGroup&gt; InstanceGroups
      {
          get { return instanceGroups; }
          set { instanceGroups = value; }
      }
  
      // snip //
  
      public void Calculate()
      {
          InstanceGroups = MyNewFilledInstanceGroup;
              if (PropertyChanged != null)
              {
                PropertyChanged(this, new PropertyChangedEventArgs("instanceGroups"));
              }
      }
  }
  </code></pre>
  
  <p>In a <code>UserControl</code> I use a <code>BackgroundWorker</code> to run the <code>Calculate</code> method, because it can take a lot of time:</p>
  
  <pre><code>BackgroundWorker worker = new BackgroundWorker();
  worker.DoWork += delegate(object o, DoWorkEventArgs args)
  {
      lock (Calculator)
      {       
          Calculator.Calculate();
      }
  };
  worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
  worker.RunWorkerAsync();
  </code></pre>
  
  <p>In the <code>XAML</code> file of the <code>UserControl</code> I have multiple bindings to the <code>Calculator</code>, like <code>{Binding Path=Calculator.InstanceGroups, Path=userControlName}</code>.</p>
  
  <p>(The overall goal is to be able to do all the work in the Calculate method on a separate thread so I can show a progress bar or something like that)</p>