如何preLOAD .NET程序集程序、preLOAD、NET

2023-09-04 12:08:18 作者:绿箭口香糖

在我的工作,我们正在开发使用.NET Framework 4,所有的应用程序都使用我们开发的,在data.dll例如数据层共同的组件不同的应用程序。这些应用程序驻留在网络驱动器,并直接从那里被发射。

At my work, we are developing different applications using .net framework 4. All the applications use common assemblies that we developed, for example the data layer in data.dll. These applications reside on a network drive and are launched directly from there.

大多数大型应用程序需要一段时间,如可能为4-5秒,发动第一次(冷启动)。随后的启动速度更快,几乎是瞬间的。我不认为它有做与网络以来的最大组装约为900KB,我们使用的是千兆网络。

Most big applications take a while, like maybe 4-5 seconds, to launch the first time (cold startup). The subsequent launches are much faster, almost instantaneous. I don't think it has to do with the network, since the biggest assembly is around 900KB and we are using a Gigabit network.

我想创建一个在计算机启动时启动一个特定目录下的所有的.NET程序集服务,而且负载。我希望,当用户启动一个程序,所有必需的组件都已经被加载和'JIT编译,所以启动要快。

I would like to create a service that starts when the computer starts, and that load all the .net assemblies under a specific directory. I am hoping that when the user launches a program, all the necessary assemblies will already be loaded and 'JITed', so the startup should be faster.

我知道如何创建一个服务,但我想知道这是否可以正常工作,因为我对CLR的理解是pretty的有限...此外,会做这样的事情Assembly.LoadFrom(文件名)合作, preLOAD的组件?如果我没有启动任何程序了一会儿,做他们留装还是他们自己卸了一段时间后?如果我改变这已经加载的程序集,会发生什么?

I know how to create a service, but I would like to know if this could work because my understanding of the CLR is pretty limited... Also, would doing something like Assembly.LoadFrom(fileName) work to preload the assemblies? If I don't launch any programs for a while, do they stay loaded or do they unload themselves after a while? What happens if I change an assembly that's already loaded?

基本上,我愿做类似的 OpenOffice的快速启动的,但对于我们自己的应用程序框架。

Basically, I would like to do something like the OpenOffice Quick starter, but for our own application framework.

谢谢大家!

---编辑--- 这interresting ... 似乎走在了正确的方式,但不是相信我明白了一切......

---EDIT--- This is interresting... seems to go in the right way but not sure I understand everything ...

推荐答案

您已经知道JIT编译是没有问题的,这也将减缓第二次创业。所有您需要做的就是在文件系统缓存中的DLL文件。所以,当你以后启动程序,它会使用该DLL的副本从缓存中,而不是通过网络连接驱动器挖找到它。这正是需要时间。办公室快速入门使用同样的伎俩。不知道谁将会赢得如果这一切preloaded东西放不下了。

You already know that JIT compiling is not the problem, that would also slow down the second start. All you have to do is get the DLLs in the file system cache. So that when you start the program later, it will use the copy of that DLL from the cache instead of digging through the network attached drive to find it. Which is what is taking time. Office Quick Start is using the same trick. Not sure who will win if all this preloaded stuff doesn't fit anymore.

只要创建一个WinForms应用程序,这样你就不会得到一个窗口,并调用的Assembly.Load()来获取组件加载,File.ReadAllBytes(),以确保整个内容是在缓存中。把一个快捷方式这个程序在启动文件夹中。你提到的那一个组件足够大到足以让从Ngen.exe温暖的开始提振。这已在每个单独的工作站上,虽然运行。

Just create a Winforms app, so you don't get a window, and call Assembly.Load() to get the assemblies loaded, File.ReadAllBytes() to ensure the entire content is in the cache. Put a shortcut to this program in the Startup folder. That one assembly you mentioned is plenty big enough to get a boost in the warm start from Ngen.exe. That has to be run on each individual work station though.