title: Changing color of text in a WPF RichTextBox from a different thread
body: <p>This is probably a really easy question, so sorry in advance if there are duplicates, but I haven't found anything about this specific problem yet.</p>
  
  <p>I have a problem with coloring specific parts of text in a RichTextBox from a different thread. I want to append a line of text to the RichTextBox and at the same time color that line with a specified color. I was able to append text and color it, but haven't been able to do so from another thread, although I was able to append plain text from the Dispatcher.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>private void UpdateTextbox(string message, Brush color)
  {
      rtbOutput.Dispatcher.Invoke((Action)(() =&gt;
          {
              rtbOutput.Selection.Select(rtbOutput.Document.ContentEnd, rtbOutput.Document.ContentEnd);
              rtbOutput.Selection.Text = message;
              rtbOutput.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, color);
          })
      );
  }
  </code></pre>
  
  <p>When I try running it from another thread I get an error message telling me the object can't be accessed, because it belongs to another thread. How do I solve this?</p>
  
  <p>Edit: Seems like the RichTextBox isn't the problem, but the Brush object is, because I can change the color just fine if I specify it inside the Invoke method, but not if I pass it as a parameter.</p>