0

I use Devexpress GridControl. And I want to change cell value according to tcp messages.

private void Form1_Load(object sender, EventArgs e)
{
        grid_mygrid.DataSource = Get_Devices_Info.Get_Device_From_DB().Tables[0];
        this.tcpListener = new TcpListener(IPAddress.Any, 2000);
                this.listenThread = new Thread(new ThreadStart(ListenForClients));
                this.listenThread.Priority = ThreadPriority.Highest;
                this.listenThread.Start();
}
private void ListenForClients()
        {
            this.tcpListener.Start();
            while (true)
            {
                TcpClient client = this.tcpListener.AcceptTcpClient();
                Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm));
                clientThread.Start(client);
            }
        }

private void HandleClientComm(object client)
        {
        ...
        try
          {
            gridView1.SetRowCellValue(row_index, "boot_progress", 50);
          }
        catch(Exception e)
          {
            if (e.InnerException != null)
               {                                            
                  Log2LogText(e.InnerException.Message);
               }
           }            
        ...
    }

if I want to try this under the thread

gridView1.SetRowCellValue(row_index, "boot_progress", 50);

if row_index=0 -> It is OK
if row_index>0 -> An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

About GridControl if i try this with button click

gridView1.SetRowCellValue(1, "boot_progress", 50); -> It is OK
gridView1.SetRowCellValue(2, "boot_progress", 50); -> It is OK
gridView1.SetRowCellValue(4, "boot_progress", 50); -> There is no row with index 4. But there is no error. It is OK.
gridView1.SetRowCellValue(5, "random_column", 50); -> There is no column with "random_column". But there is no error. It is OK.

I use try-catch but this code still give an error and program stop. When I comment this line

gridView1.SetRowCellValue(row_index, "boot_progress", 50);

there is no problem

I'm waiting for your suggestions.

BK52
  • 754
  • 2
  • 11
  • 33

1 Answers1

0

With SLaks's suggestion i seperate my UI code from my TCP. For example read this Updating a Grid datasource from a separate thread

BK52
  • 754
  • 2
  • 11
  • 33