KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm new with C# and I'm trying to make a simple client server chat application. I have RichTextBox on my client windows form and I am trying to update that control from server which is in another class. When I try to do it I get the error: "Cross-thread operation not valid: Control textBox1 accessed from a thread other than the thread it was created on". Here the code of my Windows form: private Topic topic; public RichTextBox textbox1; bool check = topic.addUser(textBoxNickname.Text, ref textbox1, ref listitems); Topic class: public class Topic : MarshalByRefObject { //Some code public bool addUser(string user, ref RichTextBox textBox1, ref List<string> listBox1) { //here i am trying to update that control and where i get that exception textBox1.Text += "Connected to server... \n"; } So how to do that? How can I update the textbox control from another thread? I'm trying to make some basic chat client/server application using .net remoting. I want to make windows form client application and console server application as separate .exe files. Here im trying to call server function AddUser from client and i want to AddUser function update my GUI. Ive modified code as you suggested Jon but now instead of cross-thread exception i've got this exception ... "SerializationException: Type Topic in Assembly is not marked as serializable" . Ill post my whole code bellow, will try to keep it simple as possible. Any suggestion is welcome. Many thanks. Server: namespace Test { [Serializable] public class Topic : MarshalByRefObject { public bool AddUser(string user, RichTextBox textBox1, List<string> listBox1) { //Send to message only to the client connected MethodInvoker action = delegate { textBox1.Text += "C
Tags (comma-separated)
Save Edits
Cancel