title: How to update a rich text box from a background worker using a delegate
body: <p>Ok I'm pretty new to using threads but so far I've managed to get the following:</p>
  
  <pre><code>Private Delegate Sub dlgUpdateText(text as string)
  
  Private Sub UpdateStatus(text as string)
    If rtxStatus.InvokeRequired then
      Dim dlg as new dlgUpdateText(AddressOf UpdateStatus)
      Me.Invoke(dlg, text)
    Else
      rtxStatus.text = text
    End If
  End Sub
  </code></pre>
  
  <p>and from my Async BackgroundWorker I call</p>
  
  <pre><code>UpdateStatus("Some text") 
  </code></pre>
  
  <p>which seems to work ok however in my original code (which generates errors because I'm updating the control from the wrong thread) I used the following code to append to the (rich)textbox:</p>
  
  <pre><code>rtxStatus.Select(rtxStatus.TextLength, 0)
  rtxStatus.SelectionColor = Color.Red
  rtxStatus.AppendText("Some error occurred gathering data")
  </code></pre>
  
  <p>My question is how should I modify my new code to allow me to do this rather than just replace the text?  I have read several guides on using delegates but I'm still lost on a few points so I don't really know what's going on with the code I have.</p>
  
  <p>Bonus questions (which probably serve best to show what needs explaining to me!):</p>
  
  <ol>
  <li>What does the Delegate Sub actually do?  It doesn't seem to serve any purpose other than hold the property (text) that was already passed to the main Sub (UpdateStatus)?</li>
  <li>What is happening when Me.Invoke is called?  Me is the current form so when I pass the Delegate Sub and the text where is it specified that the text should be passed to the rtxSTatus.Text property?</li>
  <li>UpdateStatus runs in the main thread (?) and is called from one of the background worker threads so why is the Invoke even necessary or is the UpdateStatus Sub run under the background thread that called it?  When I altered the text that is applied in the Else statement to see which was run it seems that Invoke is never used to change the text in the box.</li>
  </ol>
  
  <p>Any help would be really appreciated, I'm completely baffled by this - thanks!</p>