If I use GC.SuppressFinalize(serialPort.BaseStream), it still doesn't work in my case. Although the serial port object is not disposed by GC, the serial port can't receive data yet.

I find another way, and it works always!

I write a endless loop to check and create a new serial port object if it is disposed by GC.

while (true)

{

Thread.Sleep(60000);

if (serialPort == null)

{

serialPort = new SerialPort(portName, 9600,Parity.None,8);

serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);

serialPort.Open();

}

}

Wish it's usefull for you guys!

相关文章:

  • 2021-07-06
  • 2021-05-11
  • 2021-06-25
  • 2021-04-26
  • 2022-12-23
  • 2021-04-02
  • 2021-09-14
  • 2021-05-24
猜你喜欢
  • 2021-07-03
  • 2021-04-04
  • 2022-03-08
  • 2021-10-25
  • 2022-12-23
  • 2021-08-12
  • 2021-10-19
相关资源
相似解决方案