简体   繁体   English

如何在程序启动时加载 NetCore 使用的所有 DLL

[英]How to load all DLLs used by NetCore at program startup

I am developing wpf at dotnet5.我正在 dotnet5 开发 wpf。

DevExpress components have been added for development. DevExpress 组件已添加用于开发。

In the process of development, When you call a subwindow containing a DevExpress control It takes about 2 seconds to load the required DLL.在开发过程中,当调用包含 DevExpress 控件的子窗口时,加载所需的 DLL 大约需要 2 秒。

After loading is complete, if you close the window again and call again, it will be called immediately.加载完成后,如果再次关闭window再调用,会立即调用。

It is thought of as the time it takes to load the DLLs related to the DevExpress control.它被认为是加载与 DevExpress 控件相关的 DLL 所需的时间。

I installed DevExpress related packages through Nuget.我通过Nuget安装了DevExpress相关包。 Is there a way to preload all required package-related DLLs when the program is run?有没有办法在程序运行时预加载所有必需的与包相关的 DLL?

You could start running the static initialisers for types in specific assemblies.您可以开始为特定程序集中的类型运行 static 初始化程序。 Though you probably want to start that in a background thread.尽管您可能想在后台线程中启动它。

foreach (var a in
    AppDomain.CurrentDomain.GetAssemblies()
        .Where(a => a.GetCustomAttribute<AssemblyCompanyAttribute>()?.Company == /* todo */ )
    )
{
    foreach (var t in a.GetTypes())
        RuntimeHelpers.RunClassConstructor(t.TypeHandle);
}

But there may be further lazy initialisation that would speed up these DevExpress controls.但是可能会有进一步的延迟初始化来加速这些 DevExpress 控件。

Sort of.有点。 First note that assembly loading and JIT are happening on first call and so loading the assemblies is only part of the work.首先请注意,程序集加载和 JIT 是在第一次调用时发生的,因此加载程序集只是工作的一部分。

You can build a single file app https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file and optionally use Ahead-of-time compilation https://docs.microsoft.com/en-us/dotnet/core/deploying/ready-to-run您可以构建单个文件应用程序https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file并可选择使用提前编译https://docs.microsoft.com/en -us/dotnet/core/deploying/ready-to-run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM