当我在WPF中使用DevExpress控件时,它们所在的窗口的加载时间会增加。但是第二次访问时,它会快速加载。难道没有一种方法可以在程序启动时预加载所有需要的dll/主题(让它花费5-10秒!),但在整个程序中快速加载它们吗?我搜索了一下,找到了这样的东西:
但这些都没有帮助。首次加载仍然需要很长时间。
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));
}
但这些都没有帮助。首次加载仍然需要很长时间。