views:

352

answers:

2

I am writing a small .NET Windows Forms app, and I use the built-in Visual Studio settings to manage my programs config. I noticed an issue however that after I had added a StringCollection setting (to store a list of recently accessed documents), my program took eversoslightly longer to startup.

I ran a StopWatch over the programs initialisation and found that even calling StringCollection at all took the startup time from 100 milliseconds to 300 milliseconds. I know likely what you'll say, what's 200 milliseconds between friends?, but it seems strange to me that something so simple could cause such a delay.

So my question is, why is calling a StringCollection from the settings so slow, and is there any way I can avoid this delay?

+2  A: 

It may well be loading extra assemblies which otherwise wouldn't be needed until later on.

You could use a Console.ReadLine() call just before you load the settings and see which assemblies are loaded after that when you run it in Visual Studio to test this theory.

Jon Skeet
A good idea. As far as I can see it loads an extra assembly, with what appears to be a random name each time, such as "ks2c2gnr". I'm not savvy enough with .NET to figure out if that's important of not.
Fara
A: 

Did this happen just the first time you ran the program, or also on subsequent executions (with no rebuilding between). Also, was this a release build?

280Z28
Yes, it happens on all subsequent executions, and is the same on both release and debug builds.
Fara