为DataRow“C# slow”= hasWhatnots赋值非常慢。hasWhatnots是一个布尔值。
我已经分析了这一行,560000次点击,执行时间是82秒。当然,分析器对性能有一些影响,但它的性能仍然很慢!
关于这个问题的任何提示。DataRow是绑定到绑定到BindingSource的DataTable的一部分,绑定到DataGridView.Datasource。
发布于 2009-11-13 20:57:56
(编辑:刚刚看到您正在进行数据绑定)首先要尝试的是禁用数据绑定;也许可以将源代码设置为null,然后再重新绑定。BindingSource为此提供了SuspendBinding()、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
发布于 2009-11-13 21:55:47
你可以试试这个
bindingSource1.RaiseListChangedEvents = false;
// stuff the grid
bindingSource1.RaiseListChangedEvents = true;看看会不会有所不同。
发布于 2017-01-30 23:24:43
很晚了,但仍然有同样的问题
DataRow row
row.BeginEdit();
row["haswhatnots"] = hasWhatnots;
row.EndEdit();在(在我的规模中)大型网格(60个cols,10k+行)上出现了极端的滞后,这将cpu时间减少到不到以前的百分之一。
https://stackoverflow.com/questions/1729062
复制相似问题