[英]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. 我正在编写一个小的.NET Windows Forms应用程序,我使用内置的Visual Studio设置来管理我的程序配置。 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.
我注意到一个问题,但是在我添加了一个StringCollection设置(存储最近访问过的文档列表)后,我的程序启动时间略长。
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. 我在程序初始化时运行了一个StopWatch,发现即使调用StringCollection,启动时间也从100毫秒增加到300毫秒。 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.
我知道你会说什么,朋友之间的距离是200毫秒?但是我觉得这么简单的事情会导致这样的延迟。
So my question is, why is calling a StringCollection from the settings so slow, and is there any way I can avoid this delay? 所以我的问题是,为什么从设置调用StringCollection这么慢,有什么方法可以避免这种延迟?
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. 您可以在加载设置之前使用
Console.ReadLine()
调用,并在Visual Studio中运行它以查看此理论之后查看之后加载的程序集。
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?
此外,这是一个发布版本?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.