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?  
fbk2000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

REA_ANDREWCommented:
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
0
monarch_ilhanCommented:
Check http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_23139019.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.
0
Fernando SotoRetiredCommented:
Hi fbk2000;

If I understand you correctly the first time you create and use the Show() method on the form takes about 5 seconds and every other time after that it comes up immediately. This is the way .Net works. When you first start your application the .Net JIT compiler compiles just enough of the application to display the first form. As you create and open other forms and classes the JIT compiler needs to compile them first and then display it. Once that new form or class has been compiled into native code it is keep in memory for later use. Therefore the next time you use the form the .Net Framework needs to display that form it knows it is already compiled and gets it from memory and this is the reason why it takes longer on the first Show().

If you need to improve performance on initial startup of forms look at using ngen utility. The ngen utility will compile the .Net exe's (Microsoft Intermediate Language code) to native code which means no need for JIT.

Ngen utility:
The Native Image Generator (Ngen.exe) is a tool that improves the performance of managed applications. Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead using the just-in-time (JIT) compiler to compile the original assembly.

http://msdn2.microsoft.com/en-us/library/6t9t5wcf(VS.80).aspx

Fernando
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fbk2000Author Commented:
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.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.