C#分配一个值的DataRow [" haswhatnots"] = hasWhatnots是可怕的慢 [英] C# Assigning a value to DataRow["haswhatnots"] = hasWhatnots is awful slow

查看:137
本文介绍了C#分配一个值的DataRow [" haswhatnots"] = hasWhatnots是可怕的慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#分配一个值的DataRow [haswhatnots] = hasWhatnots是可怕的慢。 hasWhatnots是一个布尔值。

C# Assigning a value to DataRow["haswhatnots"] = hasWhatnots is awful slow. hasWhatnots is a boolean value.

我已经异形这条线,并与56万点击率的执行时间为82秒。当然,分析器对性能有一定的影响,但还是这样的表现grazy慢!

I have profiled this line and with 560000 hits the execution time is 82 seconds. Of course the profiler has some effect on the performance, but still the performance of this is grazy slow!

在这个问题上的任何提示。 DataRow中是被绑定到的BindingSource绑定到DataGridView.Datasource数据表中的一部分。

Any hints on the issue. The DataRow is part of a DataTable which is bound to BindingSource that is bound to DataGridView.Datasource.

推荐答案

(编辑:刚刚看到你的数据绑定) 首先要尝试是禁用数据绑定;也许是设置为null,并重新绑定事后源。 的BindingSource SuspendBinding() ResumeBinding() ResetBindings()这一点。

(edit: only just saw that you are data-binding) The first thing to try is disabling data-binding; perhaps set the source to null and re-bind afterwards. BindingSource has SuspendBinding(), ResumeBinding() and ResetBindings() for this.


如果真正的问题只是查找,你可以采取的一个单元的的DataColumn ,及用途:

If the real problem is just lookup, you could take a snap of the DataColumn, and use:

// early code, once only...
DataColumn col = table.Columns["haswhatnots"];

// "real" code, perhaps in a loop
row[col] = hasWhatnots;

我似乎记得,这是最快的路线(字符串超载所处的的DataColumn 从列表中)。

或者 - 使用模型而不是数据表 ;-p

Alternatively - use a class model instead of DataTable ;-p

这篇关于C#分配一个值的DataRow [" haswhatnots"] = hasWhatnots是可怕的慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆