Winforms数据网格视图在解密过程中滞后(Winforms data

编程入门 行业动态 更新时间:2024-10-25 04:25:43
Winforms数据网格视图在解密过程中滞后(Winforms data-grid view lag when decryption process)

我必须为我的办公室工作构建一些数据存储应用程序。 有了这个应用程序,我计划在Mysql数据库中存储MAC地址和Windows被许可人密钥。 我决定存储MAC地址和加密的Windows密钥而不是纯文本。 为此,我使用此加密方法

C#加密

我的问题是,当我最终解密数据网格视图中的数据时,它开始滞后得太厉害了。 即使有填充数据也需要滚动。

这是我用来解密数据网格视图数据的代码。

private void pc_count_grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == 3) { e.Value = Decrypt(e.Value.ToString()); } if (e.ColumnIndex == 4) { e.Value = Decrypt(e.Value.ToString()); } }

在解密单元格格式的数据时,如何提高数据网格视图的性能?

I have to build some data storing application for my office works. With this application I planned to store MAC address and Windows licensee Keys in Mysql database. I decided to store MAC address and windows keys encrypted rather than plain text. To do this I use this encryption method

C# encryption

My problem is when I finally decrypt the data in data-grid view the it start to lag so badly. Even with the populating data as well as scrolling.

this is a code that I used to decrypt data-grid view data.

private void pc_count_grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == 3) { e.Value = Decrypt(e.Value.ToString()); } if (e.ColumnIndex == 4) { e.Value = Decrypt(e.Value.ToString()); } }

How can I improve performance of the data-grid view while decrypting the data in cell formatting ?

最满意答案

CellFormatting事件会经常触发,因此您的解密方法将被重复调用,有时会针对相同的数据调用。 这将导致渲染显得缓慢。 您应该在从数据存储中检索值时解密这些值,然后绑定到DGV。

从MSDN ,“每次绘制每个单元格时都会发生CellFormatting事件,因此在处理此事件时应避免冗长的处理。”

伪代码:

while (r = GetNExtRecordFromMySQL()) { Foo f = new Foo(r); f.DecryptedField1 = Decrypt(f.Feild1); f.DecryptedField2 = Decrypt(f.Field2); . . . } // more code dgv1.Columns[0].Name = "Field1"; dgv1.Columns[0].DataPropertyName = "DecryptedField1"; dgv1.Columns[1].Name = "Field2"; dgv1.Columns[1].DataPropertyName = "DecryptedField2";

The CellFormatting event will fire quite often, so your decryption method will be called repeatedly, sometimes for the same data. This will cause the rendering to appear slow. You should decrypt the values while retrieving them from the data store, then bind to the DGV.

From MSDN, "The CellFormatting event occurs every time each cell is painted, so you should avoid lengthy processing when handling this event."

Pseudocode:

while (r = GetNExtRecordFromMySQL()) { Foo f = new Foo(r); f.DecryptedField1 = Decrypt(f.Feild1); f.DecryptedField2 = Decrypt(f.Field2); . . . } // more code dgv1.Columns[0].Name = "Field1"; dgv1.Columns[0].DataPropertyName = "DecryptedField1"; dgv1.Columns[1].Name = "Field2"; dgv1.Columns[1].DataPropertyName = "DecryptedField2";

更多推荐

本文发布于:2023-08-07 20:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   视图   过程中   数据   Winforms

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!