DevExpress控件为WPF加载时间 [英] DevExpress controls for WPF load time

查看:651
本文介绍了DevExpress控件为WPF加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用DevExpress控件进行WPF加载时,它们被声明的窗口增加。但是在第二次访问时,它会快速加载。没有一种方法可以在程序启动时预先加载所有需要的dll /主题(让它花费5-10秒!),但是在整个程序中加载它们很快?我搜索了一下,发现如下:

When i use DevExpress controls for WPF-load time of the window on which they are declared-increases. But on second access-it loads fast. Isnt there a way to preload all of needed dll/themes on program startup (let it took 5-10 secs!), but load them fast in overall program? I've searched a bit, found something like this:

    private static void RunTypeInitializers(Assembly a)
    {
        Type[] types = a.GetExportedTypes();
        for (int i = 0; i < types.Length; i++)
        {
            RuntimeHelpers.RunClassConstructor(types[i].TypeHandle);
        }
    }

    private static void PreloadControls()
    {
        ThemeManager.ApplicationThemeName = Theme.Office2007BlueName;

        ThemeManager.SetThemeName(new TextEdit(), Theme.Office2007BlueName);
        ThemeManager.SetThemeName(new TreeListControl(), Theme.Office2007BlueName);

        RunTypeInitializers(Assembly.GetAssembly(typeof(TextEdit)));
        RunTypeInitializers(Assembly.GetAssembly(typeof(TreeListControl)));
        RunTypeInitializers(Assembly.GetAssembly(typeof(BarManager)));

        //GC.KeepAlive(typeof(TreeListControl));
        //GC.KeepAlive(typeof(BarManager));
        //GC.KeepAlive(typeof(TreeListView));
        //GC.KeepAlive(typeof(DevExpress.Xpf.Editors.Settings.MemoEditSettings));
        //GC.KeepAlive(typeof(DevExpress.Xpf.Editors.Settings.TextEditSettings));
    }

但是没有帮助。

推荐答案

要解决此问题,我建议您 ngen 我们的程序集,并使用DXSplashWindow(11.1)或手动创建一个类似的窗口,并在主表单首次打开。

To resolve this issue, I suggest that you ngen our assemblies and use the DXSplashWindow (11.1) or create a similar window manually and show it when the main form opens for the first time.

这种减速是由JIT和主题加载引起的。

This slowdown is caused by JIT and theme loading.

简单的RunTypeInitializers调用一个对象构造函数。此时WPF主题不会加载,因为只有当控件即将被显示并生成视觉树时才会发生。

The RunTypeInitializers simply calls an object constructor. WPF themes are not loaded at this moment because this happens only when a control is about to be shown and the visual tree is generated.

这个问题的一个可能的解决方案是创建一个隐藏的窗口,其中将包含我们所有的控件,然后显示和隐藏它。但是,我不喜欢这种方法。在我看来,最好显示一个飞溅的窗口。

A possible solution to this problem is to create an invisible window which will contain all our controls, then show and hide it. However, I do not like this approach. In my opinion, it is better to show a splash window.

这篇关于DevExpress控件为WPF加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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