我正在多线程上工作,在这里我将一些数据放入数据表,然后将其分配给datagridview。为此,我做了以下
private void GetPlcData()
{
try
{
while (true)
{
dtNEW = gb.PlcReadHZLnew(IP);
System.Threading.Thread.Sleep(200);
}
}
catch (Exception ex)
{
throw (ex);
}
}
private void frmTagRead_Load(object sender,EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
Thread thPlcRead = new Thread(GetPlcData);
thPlcRead.Start();
}
private void timer2_Tick(object sender,EventArgs e)
{
try
{
DataGridView1.DataSource = dtNEW;
}
catch (Exception ex)
{
throw (ex);
}
}
现在,当我尝试将datagridview绑定到dtNew时,出现以下错误:-
请有人解决。