im trying to access a rich textbox on another form im using the following code to do so:
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
but i get the cross thread operation not valid error, i think it does this because it misses out the window.invoke part of the if statement. i also tried replacing theIf window.RichTextBox1.InvokeRequired Then to If InvokeRequired Then but it gets caught in a continues loop and a stack overflow error is thrown.
Thanks
Houlahan
I believe, on line 5,
window.Invokeshould be changed towindow.RichTextBox1.Invoke.