我必须为我的办公室工作构建一些数据存储应用程序。 有了这个应用程序,我计划在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";更多推荐
发布评论