title: Cross thread operation not valid
body: <p>im trying to access a rich textbox on another form im using the following code to do so:</p>
  
  <pre><code>Private Delegate Sub StringDelegateChat(text As String, window As ChatWindow)
      Private Sub AppendTextChatWindows(text As String, window As ChatWindow)
          Try              
              If window.RichTextBox1.InvokeRequired Then
                  window.Invoke(New StringDelegateChat(AddressOf AppendTextChatWindows), text, window)
              Else
                  window.RichTextBox1.AppendText(text)
                  window.RichTextBox1.SelectionStart = window.RichTextBox1.Text.Length
                  window.RichTextBox1.ScrollToCaret()
              End If
          Catch ex As Exception
              MessageBox.Show(ex.ToString)
          End Try
      End Sub
  </code></pre>
  
  <p>but i get the cross thread operation not valid error, i think it does this because it misses out the <code>window.invoke</code> part of the if statement. i also tried replacing the<code>If window.RichTextBox1.InvokeRequired Then</code>  to <code>If InvokeRequired Then</code> but it gets caught in a continues loop and a stack overflow error is thrown.</p>
  
  <p>Thanks
  Houlahan</p>