Hello,
I get this error when I try to run my code
"Cross-thread operation not valid:Control 'dataGridView1'accesses from a thread other than the thread it was created on"
File Name Form.cs
I have method call FillDataGrid()
FillDataGrid(string msg)
{
string[] data = msg.split(';');
string Name = data[0];
string LastName = data[1];
dataGridView1.Rows.Add(Name,LastName);
}
I call this method in a another file call Project.cs
Public class Project
{
Form1 al = new Form1();
ThreadStart th;
Thread thread;
private void Project_Startup(object sender, EventArgs e)
{
al.Show();
StartClentConnect();
}
private void StartClentConnect()
{
//connect to client
th = new ThreadStart(Recieve);
thread = new Thread(th);
thread.Start();
}
public void Recieve()
{
//connection related code
byte[] buffer = new byte[1024];
socket.Receive(buffer);
string msg = Encoding.UTF8.GetString(buffer);
string[] data = msg.Split(';');
if (data.Length > 0)
{
al.FillDataGrid(msg);
}
}
}
I get error wen the debugger reaches
dataGridView1.Rows.Add(Name,LastName); form file form1.cs
Help please havent worked on threads before..