473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Adding millions of rows to a UI control without locking up the UI?

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,
Nov 25 '05 #1
3 1308
"Danny Tuppeny" <gr****@dannytuppeny.commmmmm> a écrit dans le message de
news: 43***********************@ptn-nntp-reader04.plus.net...

| So, my question is, how do I add millions of rows to a listbox? Take the
| code below for example:

My first question to you is, what user actually wants to browse millions of
rows ????

Surely your users must know something about the items that they are looking
for; you can always set up a search dialog or integrate it into a form that
shows the list.

However, if you insist on displaying that kind of quantity of rows, then you
should use the virtual mode of a control, feeding the records on an 'as
required' basis. Just don't expect the scrollbar to be proportional to the
number of rows, just set the scroll range to three and manage it so that it
is always in the middle except when you reach one of the ends.

Your better choice is to avoid such atrocities as showing so many rows :-)

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Nov 25 '05 #2
"Joanna Carter [TeamB]" <jo****@not.for.spam> wrote in message
news:uj**************@TK2MSFTNGP09.phx.gbl...
"Danny Tuppeny" <gr****@dannytuppeny.commmmmm> a écrit dans le message de
news: 43***********************@ptn-nntp-reader04.plus.net...

| So, my question is, how do I add millions of rows to a listbox? Take the
| code below for example:

My first question to you is, what user actually wants to browse millions
of
rows ????

Surely your users must know something about the items that they are
looking
for; you can always set up a search dialog or integrate it into a form
that
shows the list.

However, if you insist on displaying that kind of quantity of rows, then
you
should use the virtual mode of a control, feeding the records on an 'as
required' basis. Just don't expect the scrollbar to be proportional to the
number of rows, just set the scroll range to three and manage it so that
it
is always in the middle except when you reach one of the ends.

Your better choice is to avoid such atrocities as showing so many rows :-)


Sorry, I wasn't clear enough. I'm not doing something this stupid - I'm
being curious :)

I've come across situations where I've only needed tens of rows, but there
was a tiny amount of processing in there, which slowed the UI down. A
solution to the above problem would also be a solution to that problem!

I can't think of exactly what I was doing to have a similar problem, but I'm
sure it must be common - needing to use the UI thread, but having something
that takes longer than the user would like to see the UI lock up for!

Danny
Nov 25 '05 #3
"Danny Tuppeny" <gr****@dannytuppeny.commmmmm> wrote in
news:43***********************@ptn-nntp-reader04.plus.net:
Hi all,

Something bugs me. It's the whole "not accessing a control from
a non-UI thread" thing...

<snip>

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.


Danny,

You can access UI elements from w/i a non-UI thread. The requirement
is that the non-UI thread has to be launched from the main UI thread.
See the documentation for System.Windows.Forms.Form.BeginInvoke.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 26 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
4
by: Federico | last post by:
Hi everybody, I'm evaluating the possibility of using MySQL 5.0 as a database backend for an application we are doing and I'd like to have hardware requirements rough estimates and/or real world...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.