-->

C#将值分配给的DataRow [“haswhatnots”] = hasWhatnots是可怕的慢

2019-10-18 07:36发布

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

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

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

Answer 1:

(编辑:刚刚看到你的数据绑定)是尝试禁用数据绑定的第一件事; 也许设置源为空并重新绑定之后。 BindingSourceSuspendBinding() ResumeBinding()ResetBindings()这一点。


如果真正的问题只是查找,您可以采取的一个单元DataColumn ,并使用:

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

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

我似乎记得,这是最快的途径(字符串超载所在的DataColumn从列表)。

或者-使用一个class模型,而不是DataTable ;-p



Answer 2:

你可以试试这个

bindingSource1.RaiseListChangedEvents = false;

// stuff the grid

bindingSource1.RaiseListChangedEvents = true;

,看看它是否有差别。



Answer 3:

很晚了,但仍然有同样的问题

DataRow row

row.BeginEdit();
row["haswhatnots"] = hasWhatnots;
row.EndEdit();

有极端的滞后,对(在我的规模)大电网存在的(60周的cols,10K +行),这板缺的CPU时间又少了百分之一到这是什么之前。



文章来源: C# Assigning a value to DataRow[“haswhatnots”] = hasWhatnots is awful slow