WPF启动缓慢的x64在.NET框架4.0缓慢、框架、WPF、NET

2023-09-02 11:49:46 作者:神经病人思维广

我发现,如果我建立我的任何CPU / x64的WPF应用程序,它需要更长的时间才能开始(大约20秒左右),或者加载比它如果开始在x86上的新控件(在发布&功放;调试模式,内部或VS之外)。这发生即使是最简单的WPF应用程序。的问题是在this MSDN线程,但没有答案提供了那里。这种情况只有在.NET 4.0 - 3.5 SP1中,64位是一样快的x86。有趣的是,微软似乎知道这个问题,因为默认情况下在VS2010一个新的WPF项目是86。

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?

编辑:可能与此有关:http://stackoverflow.com/questions/2788215/slow-databinding-setup-time-in-c-net-4-0.我使用数据绑定严重。

Possibly related to this: http://stackoverflow.com/questions/2788215/slow-databinding-setup-time-in-c-net-4-0. I'm using data binding heavily.

推荐答案

其实有两个主要的原因是,默认的项目类型为WPF应用程序为86。

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

的IntelliTrace调试只适用于x86和那会显得pretty的不好,如果默认的项目模板并没有与他们的明星的特点之一工作。 在很多开发者都还没有意识到的事实,他们值为anycpu exe文件的将是64对64位计算机上运行,​​并惊讶地发现,32位DLL的,他们依靠64位的品种,如OLEDB驱动程序不存在,某些本土DLL的,等等。

至于您所遇到的启动时间的问题,这似乎像一个问题,NGEN。由于有不同的NGEN缓存的x64和x86程序,它可能是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组件重新构建本地图像的命令。它也可能不会给你带来任何好NGEN您的应用程序,如果该程序集是不是也是在GAC所以我就懒得努力做到这一点。但框架组件,工具组件等都应NGEN'd。

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.)