title: Throws "The calling thread cannot access this object because a different thread owns it."
body: <p>I am trying to write data from serial to <code>USB</code> device to text field but it keeps throwing:</p>
  
  <blockquote>
    <p>The calling thread cannot access this object because a different thread owns it</p>
  </blockquote>
  
  <p>I know that I have to do something with dispatch or something along those lines but not sure wehre to start.  I am sure it is simple but I am drawing a blank.  Here is my code: </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  using System.IO.Ports;
  using System.Windows.Threading;
  
  namespace serial_app_one
  {
      public partial class MainWindow : Window
      {
          private SerialPortProgram _serial;
  
          public MainWindow()
          {
              InitializeComponent();
              _serial = new SerialPortProgram(this);
          }
      }
  
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      class SerialPortProgram
      {
          // Create the serial port
          private SerialPort port;
          MainWindow _window;
  
          public SerialPortProgram(MainWindow window)
          {
              _window = window;
             AppendText("Incoming Data:");
              port = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
              // Attach a method to be called when there
              // is data waiting in the port's buffer
              port.DataReceived += new
                SerialDataReceivedEventHandler(port_DataReceived);
  
              // Begin communications
              port.Open();    
          }      
  
          private void AppendText(string text)
          {                               
              _window.Dev_output.Text += string.Format("{0}{1}", text, Environment.NewLine);
          }
  
          private void port_DataReceived(object sender,
            SerialDataReceivedEventArgs e)
          {
              // Show all the incoming data in the port's buffer
              AppendText(port.ReadExisting());
          }
      }
  }
  </code></pre>