开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜