开发串口工具的时候,在接收数据时,
提示"线程间操作无效: 从不是创建控件“txtReceive”的线程访问它"
只需添加一句
Control.CheckForIllegalCrossThreadCalls = false;
完整接受代码如下
//串口接收数据
private void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (this.SP != null)
{
Control.CheckForIllegalCrossThreadCalls = false;
string dataRecive = SP.ReadExisting();
txtReceive.AppendText(DateTime.Now.ToString("yyy-MM-dd hhh:mm ->") + dataRecive + "\n");
}
}