Hi all,
Something bugs me. It's the whole "not accessing a control from a non-UI
thread" thing...
In my world, all properties would be safe from all threads (maybe they'd be
locked internally?), and paint methods/events would automatically be
marshalled into the UI thread.
It seems this isn't the case (I'm sure there are reasons, but I don't know
what they are), and code that affects the UI must be done in the UI thread.
So, my question is, how do I add millions of rows to a listbox? Take the
code below for example:
DataTable dt = ((DataSet)e.Result).Tables[0];
listCategories.Items.BeginUpdate();
listCategories.Items.Clear();
foreach (DataRow dr in dt.Rows)
{
listCategories.Items.Add(dr["CategoryName"]);
}
listCategories.Items.EndUpdate();
What's the solution if I have millions of rows? Calling DoEvents within the
loop slows things down *massively*, and calling it every x rows is messy.
I'm guessing I could set Visible to false, add all my rows in a background
hread, and then set visible to true, but that looks awful.
Then, maybe BeginUpdate/EndUpdate means I can add items on a background
thread? I don't know.
I'm just curious. In the past, I've had to do processing that was lengthy to
make the UI sluggish, but was updating the UI in a loop, making seperating
the UI-writing and the processing almost impossible.
What's the usual way of doing this kind of thing?
Thanks,