从串口频繁读取数据,关闭时卡死
发布日期:2021-10-24 03:50:06 浏览次数:1 分类:技术文章

本文共 744 字,大约阅读时间需要 2 分钟。

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:确保接收处理函数完成的标识

转载于:https://www.cnblogs.com/moisten/p/4514741.html

转载地址:https://blog.csdn.net/weixin_30687587/article/details/96944225 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:根据接口文档书写接口,并在前端调用接口返回显示出数据(加下载)
下一篇:[转]AS IS ? ??运算符

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月24日 00时44分22秒