首页 > 其他 > 详细

从串口频繁读取数据,关闭时卡死

时间:2015-05-19 16:12:45      阅读:333      评论:0      收藏:0      [点我收藏+]
public void Stop()
        {
            if (_serialPort != null)
            {
                if (_serialPort.IsOpen)
                {
                    _serialPort.DataReceived -= _serialPort_GpsReceived;
                    this._serialPort.DiscardInBuffer();
                    this._serialPort.DiscardOutBuffer();
                    int i = Environment.TickCount;
                    while (Environment.TickCount - i < 2000 && _isReceiving)
                        System.Windows.Forms.Application.DoEvents();
                    _serialPort.Close();
                }
                this._serialPort.Dispose();
                _serialPort = null;
            }
        }


_isReceiving:确保接收处理函数完成的标识

从串口频繁读取数据,关闭时卡死

原文:http://www.cnblogs.com/moisten/p/4514741.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!