码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-19 16:15:07      阅读:309      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!