C#爲DataRow賦值[haswhatnots「] = hasWhatnots非常慢。 hasWhatnots是一個布爾值。C#爲DataRow賦值[「haswhatnots」] = hasWhatnots非常慢
我已經描述了這一行,並且560000個點擊的執行時間是82秒。當然,性能分析器對性能有一定的影響,但其性能仍然非常緩慢!
有關此問題的任何提示。 DataRow是綁定到綁定到DataGridView.Datasource的BindingSource的DataTable的一部分。
C#爲DataRow賦值[haswhatnots「] = hasWhatnots非常慢。 hasWhatnots是一個布爾值。C#爲DataRow賦值[「haswhatnots」] = hasWhatnots非常慢
我已經描述了這一行,並且560000個點擊的執行時間是82秒。當然,性能分析器對性能有一定的影響,但其性能仍然非常緩慢!
有關此問題的任何提示。 DataRow是綁定到綁定到DataGridView.Datasource的BindingSource的DataTable的一部分。
(編輯:只是看到你是數據綁定) 首先要嘗試的是禁用數據綁定;也許將源設置爲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
)。
或者 - 而不是使用DataTable
;-p
一個class
模式你可以試試這個
bindingSource1.RaiseListChangedEvents = false;
// stuff the grid
bindingSource1.RaiseListChangedEvents = true;
,看看它是否有差別。
很晚,但還是有同樣的問題
DataRow row
row.BeginEdit();
row["haswhatnots"] = hasWhatnots;
row.EndEdit();
有極端滯後,存在的上(在我的規模)大電網(60周的cols,10K +行),並且該板缺的CPU時間少然後是以前的百分之一。