preloading大会 [英] Preloading Assemblies

查看:329
本文介绍了preloading大会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在工作中我们使用DevEx preSS的用户界面。首次采用DevEx preSS控制形式打开有一个长时间的停顿(有时是15-20秒在某些客户端)。在Visual Studio中,我可以看到,在该阶段被加载吨组件。有没有一种方法,以preLOAD的组件插入在所催生比如一个线程在后台的AppDomain之前的登录屏幕上弹出?

At work we use DevExpress for the user interface. The first time a form employing a DevExpress control is opened there's a long pause (sometimes 15-20 sec on some clients). In Visual Studio i can see that tons of assemblies are being loaded during that phase. Is there a way to preload that assemblies into the AppDomain in the background on a thread that is spawned for example before the login screen pops up?

推荐答案

另一种选择是强制JIT加载组件asynchronious,而不是用手工做。关键是要简单地调用控件的构造函数,所以JIT的知道它已经开始编制该特定code路径。通常,迫使它加载所有的依赖程序集。只要确保通过尝试捕捉到环绕构造函数的调用。

Another choice is to force the JIT to load the assemblies asynchronious instead of doing it by hand. The trick is to simply call the constructor of the control, so the Jit knows that it has to start compiling that particular code path. Usually that forces it to load all dependant assemblies. Just make sure to surround the call of the constructor by a try catch.

怎么做,在loadtime一个例子:

An example of how to do that at loadtime:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        PreJitControls();

        Application.Run(new Form1());
    }

    private static void PreJitControls()
    {           
        ThreadPool.QueueUserWorkItem((t) =>
        {
            Thread.Sleep(1000); // Or whatever reasonable amount of time
            try
            {
                AssemblyPullingControl1 c = new AssemblyPullingControl1();
            }
            catch (Exception) { }

            try
            {
                AssemblyPullingControl2 c = new AssemblyPullingControl2();
            }
            catch (Exception) { }

        });
    }
}

但你也可以做的登录表单的构造类似的东西,如果这是一个更好的时间做了pre加载。只需将preJitControls法的登录表单,并从构造函数调用它。

But you could also do something similar in the constructor of the login form, if that is a better time to do the pre-loading. Just move the PreJitControls method to the login form and call it from the constructor.

这篇关于preloading大会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆