Search code examples
c#.netsettingsstringcollection

Why is calling StringCollection from Settings slow?


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?


Solution

  • 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.