views:

921

answers:

2

I have a Windows Form that takes quite a bit of time to load initially. However, each subsequent request to load the Form doesn't take as long. Is there a way to optimize a Form's load time?

+9  A: 

You can use ngen.

I also use this tip to reduce the Memory footprint on startup.

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.

Gulzar
Note that you lose the benefits of JITting when you use NGEN. One thing you can do is put the Form in an NGENed EXE and the rest of the application logic in a DLL that isn't NGENed.
Mark Cidade
Good tip marxidad. if you can post it as an answer, one upvote from me :)
Gulzar
A great answer from Will Dean below.
Gulzar
+4  A: 

You need to find out where the time is going before you can optimise it. Don't just ngen it without finding that out first, as if the problem is loading a 150MB background bitmap resource then you won't have done anything useful at all with ngen.

You should disregard all specific advice or hunches about optimisation which arise without any measurements being made.

Will Dean
This is very true. Do you have any methods of finding potential bottlenecks?
Bryan Roth