Link to home
Start Free TrialLog in
Avatar of fbk2000
fbk2000

asked on

Slow loading of a ListView on first Display - C# VS2008

Using VS2008. C#

I have a form with a ListView on it.

I create the form, and then load around 30,000 items into the listview from the database.  

The loading takes less than a second, but the first time I call Show(),  on the form, it takes around 5 seconds for the form to come up.  The next time do a Show(), it comes up immediately.  

What can I do, if anything, during the initialization phase to make it ALWAYS come up in less than a second?  Is there some way to pre-load the graphics or run the show() invisibly?  
Avatar of REA_ANDREW
REA_ANDREW
Flag of United Kingdom of Great Britain and Northern Ireland image

Are you loading the items on form load and syncronously?

Why not try loading the items aysncronously, and simply informing the user with a loading message or something.  This way the Form opens and the thread it uses has no job but to open the window.  The separate thread it will use to load the list box will not affect the form showing.

Andrew
Check https://www.experts-exchange.com/questions/23139019/How-do-I-see-individual-Items-added-to-a-Winform-Listbox-control-as-they're-added-at-runtime.html

I agree with andrew. If you are populating 30000 records, it means a delay will occur in any case if you do this within a single thread.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fbk2000
fbk2000

ASKER

Please read the question thoroughly before answering.

"The loading takes less than a second...."   Loading is not the issue, nor is the database query time, etc.  All the data gets into the control immediately. So loading Asynch is not really relevant; moreover, I would need this control ready to run as soon as the user  sees the form.

Fernando is correct.  I was able to fake out the JIT, by showing the form and then immediately hiding it during load.  The reason the native code was not already compiled during the showing of the main form (it would normally be the same code for the show() method)  is because the main application form is a WPF Window, which of course is a completely different object than the WinForm.