there is a method

public static void GetMessages() { string Message = "12345" ChatBox.AppendText(Message + Environment.NewLine); ChatBox.SelectionStart = form.ChatBox.TextLength; ChatBox.ScrollToCaret(); } 

which runs in a separate thread. An error occurs when attempting to access richTextBox (ChatBox). How do I change the chatbox from this method?

    1 answer 1

    The Windows window system uses a single-threaded apartment model (STA), so you can only access the control from the thread that created it. The easiest way to solve this problem is to check the Control.InvokeRequired property and call the Control.Invoke () method.

    By the way, this method is not the only one. The second option is described here .