Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code

C#
int i = 0;
    while(i < 1000000)
    {
        list.addItem("v", i);
        i = i + 1;
    }


this works fine but, is very inefficient because the program stops responding while adding a large amount, I was wondering if there is better code then this? I want it to add the numbers into the listbox or combobox with-out this lagging, is this possible?
Posted
Comments
max_nowak 13-Aug-13 3:58am    
If you intend to add 1000000 items to your control on your gui, then I think there's no way around of dealing with some lag. Anyway, why would you even want to do that? What's your use case?
[no name] 13-Aug-13 4:08am    
I intent on making a program which generates seeds for mincraft, and allow the user get a huge amount to choose from, I want it to be a very unique, seed generator and nor like the rest.
max_nowak 13-Aug-13 4:17am    
You could still split up the work of filling the list in multiple threads. Say, one thread handles the first 500000 and at the same time the second thread starts from 500000 and runs till 1000000
Richard MacCutchan 13-Aug-13 5:54am    
That's like using a steamhammer to crack a nut, and all you are getting is the sequenc 1 to 1000000. Use the Random() method to generate more truly random numbers.
[no name] 13-Aug-13 5:55am    
I did that, just didn't show it

Different approach:

make up a textbox, limit the values and validate entered numbers.
 
Share this answer
 
My advice would be to create a number of cascade lists.

First list has:

0 - 99999
100000 - 199999
200000 - 299999
e.t.c.

Second list break down the next choice into a similar number of options.

0 - 9999
10000 - 19999
e.t.c.

And repeat until an exact number is selected.

That way you shouldn't have more than 100 list items over several lists.
 
Share this answer
 
v2
If you want to add content to a listbox or anything similar try using a StringBuilder instead of writing one at a time (bulk add your content), see here : http://docs.oracle.com/javase/tutorial/java/data/buffers.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900