title: Update treeview from another thread
body: <p>I'm quite new to threads in c# (WPF) and since I've implemented some label and progressbar update  successfully, I do not understand Why when I try to add items to the treeView of my GUI from another class called in a separate thread I get an exception: </p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.InvalidOperationException'
    occurred in WindowsBase.dll</p>
    
    <p>Additional information: The calling thread cannot access this object
    because a different thread owns it.</p>
  </blockquote>
  
  <p>My update treeview code is this:</p>
  
  <pre><code>private void updateTreeView(TreeView tree, List&lt;TreeViewItem&gt; items, Boolean clear) {
              tree.Dispatcher.Invoke(new Action(() =&gt; {
                  if (clear) {
                      tree.Items.Clear();
                  }
                  ItemCollection treeitems = tree.Items;
                  foreach (TreeViewItem item in items) {
                      treeitems.Dispatcher.Invoke(new Action(() =&gt; {
                          treeitems.Add(item);
                      }));
                  }
                  tree.ItemsSource = treeitems;
              }));
          }
  </code></pre>
  
  <p>And the exception points at the line:</p>
  
  <blockquote>
    <p>treeitems.Add(item);</p>
  </blockquote>
  
  <p>Thanks in advance.</p>