https://blog.csdn.net/fengda2870/article/details/51554838
上面的链接给出了提示: 将Invoke变为BeginInvoke。
亲测可行。
private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (this.InvokeRequired) { this.BeginInvoke(new DataReceived(SerialPort_DataReceived), sender, e); //DataReceived为代理类型 return; } if (!SerialPortRuning) { SerialPortRuning = true; try { // 接收串口数据 } catch (Exception ex) {
} finally { SerialPortRuning = false; } } }
下面还有一篇关于串口相关的介绍:
C# 串口操作系列(2) – 入门篇,为什么我的串口程序在关闭串口时候会死锁 ?
出处:https://blog.csdn.net/qq_27508477/article/details/87719668