English 中文(简体)
C# Assigning a value to DataRow["haswhatnots"] = hasWhatnots is awful slow
原标题:

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

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!

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

问题回答

(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.


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;

I seem to recall that this is the fastest route (the string overload locates the DataColumn from the list).

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

You could try this

bindingSource1.RaiseListChangedEvents = false;

// stuff the grid

bindingSource1.RaiseListChangedEvents = true;

and see if it makes a difference.

Very late, but still had the same issue

DataRow row

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

There were extreme lags, occuring on (in my scale) large grids (60 cols, 10k+ rows), and this cutted the cpu time to less then one percent to what it was before.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签