c#串行通信winform ui冻结

发布于 2025-01-27 21:34:11 字数 532 浏览 1 评论 0原文

我正在研究发生全双工串行通信的应用程序(读/写)。具体来说,我每40毫秒内从端口读取256个字节,然后回信其他256个字节。

除此之外,我在WinForm中还有很多文本框,当收到256个字节的数据时,我会根据接收到的数据更新每个文本框。为此,我在Winform类中进行了以下操作:

  1. 在SeriaLdatAtaTaReceIvedEventHandler方法中读取数据(例如port.read.read(ReadData,0,256)

  2. 数据。 (例如textbox1.text = convert.tostring(readdata [0]

  3. 完成更新后,将另一个256个字节写入端口(例如port.write(eg code> port.write)(Writedata,, 0,256))

我的问题是UI保持冻结,我无法在UI上显示所有读取消息由于我不使用任何螺纹或异步机制。如何在不冻结的情况下使Winform显示每条消息?

I am working on an application where a full-duplex serial communication occurs (Read/Write). Specifically, I read 256 bytes of data from a port in every 40 ms and write back other 256 bytes.

In addition to this, I have bunch of TextBoxes in WinForm and when 256 bytes of data is received, I update each TextBox based on the received data. To be able to do that, I did the following in a WinForm class:

  1. Read the data in SerialDataReceivedEventHandler method (e.g. port.Read(readData, 0, 256))

  2. Call UpdateUI() method (within the SerialDataReceivedEventHandler method) which updates the UI elements based on the received data. (e.g. textBox1.Text = Convert.ToString(readData[0])

  3. After finishing the UpdateUI, write another 256 bytes of data to the port (e.g. port.Write(writeData, 0, 256))

My problem is that UI keeps freezing and I cannot display every read messages on UI since I don't use any threading or async mechanism. How can I make WinForm display every message without freezing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文