title: How to solve cross Thread Operation not valid in windows form?
body: <p>I have been stuck here .....I am creating a  chat server windows application,which will host and all client will register </p>
  
  <p>let me explain my scenario,when i start a chat server.....I have used TextBox name ChatTextBox,in which i try to get all registered client Ip address</p>
  
  <p>But when i try to register a client on server it shows cross thread operation is not valid,how to solve it ????</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Net;
  using System.Net.Sockets;
  using System.Windows.Forms;
  using System.Threading;
  
  namespace Myservercheck
  {
  public partial class Form2 : Form
  {
      TcpListener myli;
      TcpClient clientSocket = default(TcpClient);
      string s=string.Empty;
  
      public Form2(TcpListener tc)
      {
          myli = tc;
          InitializeComponent();
  
      }
  
      private void Form2_Load(object sender, EventArgs e)
      {
          IPlistBox.Items.Add(myli.LocalEndpoint.ToString());
          chattextBox.Text= "Chat server started on selected IP &amp; Port Number:\n"+myli.LocalEndpoint.ToString();
          chattextBox.AppendText("\n");
          chattextBox.AppendText("Waiting for connections............\n");
          myli.Start();
         Thread thread1 = new Thread(listern);
         thread1.Start();
          chattextBox.AppendText("\n");
  
  
      }
  
  
      public void listern()
      {
          while (true)
          {
  
              clientSocket = myli.AcceptTcpClient();
              IPAddress tempAddress = ((IPEndPoint)(clientSocket.Client.RemoteEndPoint)).Address;
              chattextBox.Text = tempAddress.ToString();
              chattextBox.AppendText("Connection accepted from:" + s);
          }
          }
      }
  
  
  
  
      }
  </code></pre>