开发者

Does .Net load references up front, or only when it needs them?

开发者 https://www.devze.com 2023-01-08 03:58 出处:网络
If a .Net exe has a normal reference to a .Net assembly, will it load the assembly immediately when the exe is loaded, or will it wait until a class from the referenced asse开发者_开发知识库mbly is us

If a .Net exe has a normal reference to a .Net assembly, will it load the assembly immediately when the exe is loaded, or will it wait until a class from the referenced asse开发者_开发知识库mbly is used?


Assemblies are loaded dynamically as they are needed. This code snippet shows how you can log assemblies as they are loaded:

    private static void InitializeAssemblyMonitor()
    {
        // Register for load event first
        AppDomain.CurrentDomain.AssemblyLoad +=
            delegate( object sender, AssemblyLoadEventArgs e )
            {
                LogAssembly( e.LoadedAssembly );
            };

        // Now log any assemblies that are already loaded
        foreach ( Assembly assembly in AppDomain.CurrentDomain.GetAssemblies() )
            LogAssembly( assembly );
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消