简体   繁体   English

从Visual Studio启动时,WPF应用程序加载初始窗口非常慢

[英]WPF Application very slow to load initial window when launched from Visual Studio

I have a relatively simple WPF application. 我有一个相对简单的WPF应用程序。 Whenever I launch it from within Visual Studio 2012 (in Debug or Release mode), it is very slow to start up (can literally take minutes). 每当我从Visual Studio 2012中启动它时(在调试或发布模式下),它启动起来都很慢(可以花费几分钟)。 There is some custom initialization work done (reading files and loading data from a SQLite database), but it should be completed within 1s as it takes less time than that when I launch the application directly by clicking on the Debug/myapp.exe file. 有一些自定义初始化工作(读取文件和从SQLite数据库加载数据),但它应该在1s内完成,因为它比我通过单击Debug / myapp.exe文件直接启动应用程序所需的时间更少。

The strange behavior is that if I break the execution and immediately continue ("play" button in the IDE), the window will load instantly. 奇怪的行为是,如果我中断执行并立即继续(IDE中的“播放”按钮),窗口将立即加载。 If I press F5 "Start Debugging" the problem will arise, but it will load instantly if I press Ctrl+F5 "Start without debugging". 如果我按F5“开始调试”会出现问题,但如果我按下Ctrl + F5“启动而不调试”,它会立即加载。

I am using .NET 4.5 in x86 mode. 我在x86模式下使用.NET 4.5。

I tried profiling using dotTrace Performance profiler but the problem cannot be reproduced this way (it will load instantly). 我尝试使用dotTrace性能分析器进行分析,但问题无法以这种方式重现(它会立即加载)。

Do you have any idea about what could be causing this? 你对这可能导致什么有什么想法吗?

On possibility for this slowness could be caused by having too many WPF Trace Settings turned on. 由于打开了太多的WPF跟踪设置,可能会造成这种缓慢的可能性。 If this is the problem, you can tell because the Output Window will be filling with information as the project starts up. 如果这问题,您可以告诉,因为在项目启动时输出窗口将填充信息。

If this is your problem, you can adjust your Trace Settings by going to 如果这您的问题,您可以转到进行调整跟踪设置

Tools > Options > Debugging > WPF Trace Settings 工具>选项>调试> WPF跟踪设置

Once you have found the correct section, you can turn the various trace options off and you should see an improvement in speed upon starting the application. 找到正确的部分后,您可以关闭各种跟踪选项,并且应该会在启动应用程序时看到速度的提高。

There could be a large amount of breakpoints set in code. 代码中可能设置了大量断点。 Open the Breakpoints window (Debug->Windows) and turn it all off to see, if it's the reason. 打开Breakpoints窗口(Debug-> Windows)并将其全部关闭以查看是否是原因。 Or even better, you can delete from disc the .suo user file, which stores breakpoints and session settings. 或者甚至更好,您可以从光盘中删除.suo用户文件,该文件存储断点和会话设置。

Another possible reason is a malfunctioning extension. 另一个可能的原因是扩展功能失灵。 You may want to try to disable some plugins to see, if it works better. 如果效果更好,您可能想尝试禁用某些插件来查看。

Also, I remember I experienced WPF apps start slowly from VS, if the active tab was graphical window preview. 此外,我记得我经验丰富的WPF应用程序从VS开始,如果活动选项卡是图形窗口预览。

In my case the problem was that for some reason VS doesn't cache symbols for System.Windows.Interactivity.dll and every time I start debug session they're downloaded from server. 在我的情况下,问题是由于某种原因VS不会缓存System.Windows.Interactivity.dll的符号,每次我启动调试会话时,它们都是从服务器下载的。 Navigating to Tools -> Options -> Debugging -> Symbols and selecting "Only specified modules" with empty module list addressed the delay. 导航到Tools -> Options -> Debugging -> Symbols并选择带有空模块列表的"Only specified modules"来解决延迟问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM