WPF 在 .NET Framework 4.0 中的 x64 上启动缓慢 [英] WPF slow to start on x64 in .NET Framework 4.0

查看:39
本文介绍了WPF 在 .NET Framework 4.0 中的 x64 上启动缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,如果我为 Any CPU/x64 构建 WPF 应用程序,启动(大约 20 秒)或加载新控件所需的时间比在 x86 上启动(在发行版中)要长得多& 调试模式,在 VS 内部或外部).即使是最简单的 WPF 应用程序也会发生这种情况.this MSDN thread<中讨论了该问题/a>,但那里没有提供答案.这仅在 .NET 4.0 中发生——在 3.5 SP1 中,x64 与 x86 一样快.有趣的是,微软似乎知道这个问题,因为 VS2010 中新的 WPF 项目的默认值是 x86.

I've noticed that if I build my WPF application for Any CPU/x64, it takes MUCH longer to start (on the order of about 20 seconds) or to load new controls than it does if started on x86 (in release & debug modes, inside or outside of VS). This occurs with even the simplest WPF apps. The problem is discussed in this MSDN thread, but no answer was provided there. This happens only with .NET 4.0 -- in 3.5 SP1, x64 was just as fast as x86. Interestingly, Microsoft seems to know about this problem since the default for a new WPF project in VS2010 is x86.

这是一个真正的错误还是我做错了?

Is this a real bug or am I just doing it wrong?

可能与此有关:C# .NET 4.0 中的慢数据绑定设置时间.我正在大量使用数据绑定.

Possibly related to this: Slow Databinding setup time in C# .NET 4.0. I'm using data binding heavily.

推荐答案

实际上,WPF 应用程序的默认项目类型是 x86 有两个主要原因.

Actually there's 2 main reasons that the default project type for WPF applications is x86.

  • Intellitrace 调试仅适用于 x86,如果默认项目模板无法与它们的明星功能之一配合使用,那看起来会很糟糕.
  • 许多开发人员仍然不知道他们的 AnyCPU exe 将在 64 位机器上作为 x64 运行,并且惊讶地发现他们依赖的 32 位 DLL 在 64 位版本中并不存在,例如 OLEDB 驱动程序、某些本机DLL 等.

至于您遇到的启动时间问题,这几乎像是 NGEN 的问题.由于 x64 和 x86 进程有不同的 NGEN 缓存,可能需要重建或更新 64 位 NGEN 缓存.尝试从提升的命令提示符运行以下命令:

As for the startup time issues you're experiencing, it almost seems like an issue with NGEN. Since there are different NGEN caches for x64 and x86 processes, it could be that the 64 bit NGEN cache either needs to be rebuilt or updated. Try running the following from an elevated command prompt:

CD C:WindowsMicrosoft.NETFramework64v4.0.30319
NGEN update

这是为已标记为 NGEN 的程序集重新构建本机映像的命令.如果程序集不在 GAC 中,它也可能对 NGEN 您的应用程序没有任何好处,所以我不会费心去尝试这样做.但是框架程序集、工具包程序集等都应该是 NGEN 的.

This is the command to re-build native images for assemblies that have already been marked for NGEN. It also probably won't do you any good to NGEN your application if the assemblies are not also in the GAC so I wouldn't bother trying to do that. But framework assemblies, toolkit assemblies, etc should all be NGEN'd.

(顺便说一句,当我运行上述关于无法加载的程序集的命令时,我确实遇到了几个错误.主要是 SQL 和 Visual Studio 程序集.)

(By the way, I did get several errors when I ran the above command about assemblies that could not be loaded. It was mostly SQL and Visual Studio assemblies.)

这篇关于WPF 在 .NET Framework 4.0 中的 x64 上启动缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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