473,769 Members | 6,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Res ult).Tables[0];
listCategories. Items.BeginUpda te();
listCategories. Items.Clear();
foreach (DataRow dr in dt.Rows)
{
listCategories. Items.Add(dr["CategoryNa me"]);
}
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 1329
"Danny Tuppeny" <gr****@dannytu ppeny.commmmmm> a écrit dans le message de
news: 43************* **********@ptn-nntp-reader04.plus.n et...

| 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******** ******@TK2MSFTN GP09.phx.gbl...
"Danny Tuppeny" <gr****@dannytu ppeny.commmmmm> a écrit dans le message de
news: 43************* **********@ptn-nntp-reader04.plus.n et...

| 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****@dannytu ppeny.commmmmm> wrote in
news:43******** *************** @ptn-nntp-reader04.plus.n et:
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.Begi nInvoke.

--
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
6786
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 one, and only one parent. The depth should not exceed 6 or 7 levels. The initial import will have about 6 million leaves, and 3 million branches. I would expect the leaves to grow significantly, in number easily tripling. However, the branches will...
4
5482
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 dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
3
4885
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 the best method? Do you have a sample of how to do this?
4
4898
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 experience from people that are already running similar dimensioned database/application. As a rought estimate the database has around 80 tables 4-5 of these are supposed to grow up to 5.000.000 records another 30% will be in the 100.000 range...
0
9424
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10051
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10000
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.