c#串行通信winform ui冻结
我正在研究发生全双工串行通信的应用程序(读/写)。具体来说,我每40毫秒内从端口读取256个字节,然后回信其他256个字节。
除此之外,我在WinForm中还有很多文本框,当收到256个字节的数据时,我会根据接收到的数据更新每个文本框。为此,我在Winform类中进行了以下操作:
在SeriaLdatAtaTaReceIvedEventHandler方法中读取数据(例如
port.read.read(ReadData,0,256)
)- 数据。 (例如
textbox1.text = convert.tostring(readdata [0]
) 完成更新后,将另一个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:
Read the data in SerialDataReceivedEventHandler method (e.g.
port.Read(readData, 0, 256)
)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]
)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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论