3

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?

Alex McBride
  • 6,881
  • 3
  • 29
  • 30

2 Answers2

3

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
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 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. – Alex McBride Jul 15 '09 at 21:16
1

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?

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280