C# SerialPort 串口通信多线程问题

编程新手,想C# SerialPort实现串口通信,写的程序大概这样一个结构。发送一个数据后,要求收到下位机回复,超时发送下一个数据。要加一个发送和接收的线程,是加在主程序里面吗?大体的结构应该是怎么样的?求大神帮助!O(∩_∩)O谢谢!
class SendAndReceive
{
SerialPort sp = new SerialPort();

    public void SearchSet()//检测有哪些端口

    public void PortSet()//端口设置

    public void DataStartSend(byte[] sendbyte)
    {
        sp.Open();
        //调用crc函数计算crc16的值
        sp.Write(sendbyte, 0, sendbyte.Length);

    }
    public void DataReceive()
    {
        byte[] receivebyte=new byte[8];
        sp.Read(receivebyte, 0, receivebyte.Length);
        //crc校验结果
    }

}

第一发送线程肯定要从主线程上创建。
发送线程采用一个欲发送队列,每发送一个数据就用线程消息阻塞线程一定的时间,如收到回复线程恢复线程的消息发送下一个数据,或超时发送下一个数据

AutoResetEvent myResetEvent = new AutoResetEvent(false); 用它

第二接收可以采用接收触发事件。

 serialPort.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
 在这个事件里如果收到你要的对应数据就让发送线程放行,发送下一个数据。
如果你不想用自己可以在每次发送时new一个新线程这个线程只负责读取你要接收的下一条数据。如果读的到就让发送线程放行,读不到在超时事件后结束线程。



你要添加一个串口接收数据事件,serialPort.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);然后把接收字节类型的数据代码写在函数port_DataReveived里

然后多线程的话好像要用到thread