title: Thread Cannot Access Object
body: <p>I have a UserControl that is added to my Main window.  The Main code continuously receives TCP messages and interacts with the UserControl accordingly.  One of the UserControl's methods that is called by Main is AddMessage:</p>
  
  <pre><code>internal void AddMessage(Paragraph p)
  {
      if (txtViewer.Dispatcher.CheckAccess())
      {
          txtViewer.Document.Blocks.Add(p);
      }
      else
      {
          Dispatcher.Invoke(new Action(() =&gt;
              {
                  txtViewer.Document.Blocks.Add(p);
              }
          ));
      }
  }
  </code></pre>
  
  <p>The line within Dispatcher.Invoke always throws an InvalidOperationException.  I've looked around at similar issues, and most of them were cases where the Dispatcher wasn't being used, so I don't know why my code isn't working.  I suppose I'm using it incorrectly, or it may have something to do with the Paragraph object being passed between threads.</p>
  
  <p>Thanks,
  Jared</p>