串口:由于线程退出或应用程序请求,I/O 操作已中止
虚拟串口com2向com1发送10个字节数据。屡次发生如下错误。不要try....catch{...}
上代码:
错误:由于线程退出或应用程序请求,I/O 操作已中止。
异常现象,当serialPort1_DataReceived执行完成以后,它自动又执行了一次serialPort1_DataReceived,而且e.EventType 是chars,此时出现如上错误,为什么?
偶尔会出现一次全过程都无异常的现象,为什么?
不要告诉我加try....catch{...},我想知道错误的根本原因。谢谢~~~~
上代码:
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
if (e.EventType == System.IO.Ports.SerialData.Eof) return;
byte[] b = new byte[20];
serialPort1.Read(b, 0, b.Length);//第二次进入异常
if (pictureBox1.InvokeRequired)
this.pictureBox1.BeginInvoke(new drawdel(draw), b);
else
draw(b);
}错误:由于线程退出或应用程序请求,I/O 操作已中止。
异常现象,当serialPort1_DataReceived执行完成以后,它自动又执行了一次serialPort1_DataReceived,而且e.EventType 是chars,此时出现如上错误,为什么?
偶尔会出现一次全过程都无异常的现象,为什么?
不要告诉我加try....catch{...},我想知道错误的根本原因。谢谢~~~~
...全文


