DataGridView Invokerequired Works工作慢

发布于 2025-02-03 10:58:28 字数 616 浏览 2 评论 0原文

我正在开发用于记录RS232数据的软件。每个毫秒收到了很多数据。收到的数据存储在DataGridView中,您可以在附件图片上看到。 对于填充数据,我使用datagridview1.invokerequrequred serialport1_datareceived事件。 当RS232上只有几个数据时,它可以正常工作。但是,当它收到RS232 RS232的许多数据包时,GUI的工作缓慢。按下按钮没有反应,应用程序会消耗CPU。一旦我断开RS232实际上没有新数据,按钮立即按下响应。 我的第二种方法是直接从serialport1_datareceived事件中使用datagridview1.rows.add。在这种情况下,它运行迅速,按钮负责。但是DataGridView1不会刷新,有时会闪烁。我已经在使用双重缓冲。

所以我的问题是:

  1. 如何使用Invokerequired加速?
  2. 如何在填充datagridview1.rows.add的serialport1_dataReceived后刷新datagridview1?

在此处输入图像描述

I'm developing software for logging data from RS232. There is a lot of data received each millisecond. Received data is stored in datagridview, you can see on attached picture.
For filling data I use dataGridView1.InvokeRequired from serialPort1_DataReceived event.
It works fine when there is just a few data on RS232. But when it receives many packets from RS232 GUI is working slow. There is no reaction for buttons pressing, and application consumes CPU. Once I disconnect RS232 physically there is no new data, buttons pressing response immediately.
My second approach was using dataGridView1.Rows.Add directly from serialPort1_DataReceived event. In this case it works fast, buttons are responsible. But dataGridView1 doesn't refresh, and some times flicker. I'm already using double buffering for it.

So my questions are:

  1. How to speed up using InvokeRequired?
  2. How to refresh dataGridView1 after filling dataGridView1.Rows.Add from serialPort1_DataReceived?

enter image description here

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

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

发布评论

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