蓝狐在DotNet中的思考 BlueFox Thinking in DotNet...
交流,分享,探讨DotNet技术...... Communion,Share, and Discuss about DotNet Technology.....

导航

统计
公告
 

2011年7月22日

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!

posted @ 2011-07-22 10:56 蓝狐 阅读(152) 评论(0) 编辑