为什么GetMessageW占用大量的CPU使用率在我的WPF应用程序? [英] Why would GetMessageW take up massive CPU usage in my WPF application?

查看:633
本文介绍了为什么GetMessageW占用大量的CPU使用率在我的WPF应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个严重的头饼刷我的手在这里。我调查的性能问题,在我们的应用程序中的WPF的组成部分。

I've got a serious head-scratcher on my hands here. I'm investigating performance issues with a WPF component in our application.

我们的.NET应用程序是非常大的,而且几乎完全是在Windows窗体。作为一项新举措的一部分,我们改写了我们的核心成分具有丰富的WPF界面之一。有很多的WinForms&LT的; - > WPF互操作怎么回事这个东西粘合在一起,我怀疑可能以某种方式与我所看到的

Our .net application is very large, and almost entirely in windows forms. As part of a new initiative we rewrote one of our core components with a rich WPF ui. There is a lot of WinForms<-->WPF interop going on with this thing to glue it together, and I suspect that may be somehow related to what I'm seeing.

在我的配置文件操作缓慢蚂​​蚁探查,我看到发生的功能UnsafeNativeMethods.IntGetMessageW内大量的活动。蚂蚁报告尽可能多的CPU活动去那里,因为它向我们所有的业务逻辑和WPF渲染的东西结合起来。有没有管理$​​ C $ C,它使用的是循环的功能下线,所以无论IntGetMessageW是做有我后。

When I profile the slow operation in ANTS profiler, I see a lot of activity occurring inside the function UnsafeNativeMethods.IntGetMessageW. ANTS reports as much CPU activity going there as it does to all of our business logic and wpf rendering stuff combined. There is no managed code downline of that function that is using the cycles, so whatever IntGetMessageW is doing there is what I'm after.

我不是特别精通Win32编程,但我知道在这方面的消息循环的基础。没有什么我看到这里虽然是什么,我们做手工 - 在我们的code没有意义的,我们直接用其中任何一种底层消息循环本身,或者,可以在WPF访问的更复杂的东西互动调度员。

I'm not particularly well-versed in win32 programming, but I know the basics of a message loop in that context. None of what I'm seeing here though is anything we do manually -- at no point in our code are we interacting directly with either the underlying messageloop itself, or any of the more complicated stuff that can be accessed on the WPF dispatcher.

在这里开始质疑我们的WPF组件写入从窗口继承(即它不只是一个控制/用户控件),和我们显示它使用的ShowDialog我们是用来调用ShowDialog的旧的WinForms版本的更高水平的逻辑零件。有迹象表明,我们已经使用了WPF成分的内部以preserve兼容性与我们的一些现有件无法在WPF重写某些WindowsFormsIntegrationHost控制。

Our WPF component in question here is written inheriting from Window (ie. it's not just a control/usercontrol), and we show it using ShowDialog out of our higher level logic that used to call ShowDialog on the old WinForms version of this component. There are some WindowsFormsIntegrationHost controls that we have used inside of the WPF component to preserve compatibility with some of our existing pieces that could not be rewritten in WPF.

我一直在研究这个了几天,但从来没有发现一大堆去。我不断发现谈谈输入消息(鼠标和键盘)没有关联的帖子,但我不知道我能做些什么来验证;我已经尝试过屠杀的code,除去每次鼠标/键盘操作我可以。

I've been researching this for days, but have never found a whole lot to go on. I keep finding vaguely related postings that talk about input messages (mouse and keyboard), but I don't know what I can do to verify that; I've already tried butchering the code to remove every mouse/keyboard operation I could.

我有一个很难成气候,主要是因为这条线code是完全隔离(而不是父母或任何东西的孩子,我可以指出,作为实际从我们的code到来),并完全不透明关于它在做什么。

I'm having a hard time getting anywhere primarily because this line of code is completely isolated (not a parent or child of anything I can point out as actually coming from our code), and completely opaque about what it is doing.

下面是一个蚂蚁的图像调用ShowDialog的函数调用展示到这里的路径图:

Here is an image of an ANTS call graph of the ShowDialog function showing the path of calls to get here:

我充分认识到,这可能是东西,只是有许多工作要做为WPF的一部分(虽然我们已经写在WPF中不显示此行为的其他组分),或者说,这仅仅是一个很奇怪的错误,在蚂蚁探查,但在这一点上我需要验证,或另一种方式。如果有人能告诉我什么是或可能是这里发生了 - 或点我一些方法,我将能够找出自己,我会直接种种好人缘的方式

I fully realize that this could be something that just has to be done as part of WPF (although other componenets we have written in WPF don't display this behavior), or that this is just a very strange bug in ANTS profiler, but at this point I need to verify it one way or another. If anyone can tell me what is or might be going on here -- or point me to some way I would be able to figure it out myself, I will direct all kinds of good karma your way.

更新: 在回答下面的一些讨论,这里是从蚂蚁另一种观点 - 这更好说明了困惑我有(这是蚂蚁查看CPU时间模式)。我急忙审查我们的code部位,但没有一个系统的相关功能:

UPDATE: In response to some discussion below, here is another view from ANTS -- this one better illustrates the confusion I am having (this is with the ANTS view in "CPU time" mode). I've hastily censored parts of our code, but none of the system related functions:

为寻找谢谢!

推荐答案

我发现这一点的同时寻找在同一个问题的信息。我将添加我所知道的,看看是否有帮助:

I found this while searching for information on the same issue. I'll add what I know and see if it helps:

我在WinXP的机器上运行 - WPF框架更加一体化在Vista和Win7的比在XP。一些这可能是由于如何WPF运行上面的XP桌面的,而不是在它

I'm running on a WinXP box - the WPF framework is more integrated in Vista and Win7 than it is in XP. Some of this could be due to how WPF runs "on top" of the XP desktop, rather than within it.

我运行一个纯粹的本地WPF应用程序 - 没有的WinForms或其他code

I'm running a pure native WPF application - with no WinForms or other code.

我遇到了这个设法确定为什么简单地滚动窗口将消耗100%的CPU和口吃,在做的。

I ran into this trying to determine why simply scrolling a window would consume 100% CPU and stutter while doing it.

运行AQtime性能分析器,我看到IntGetMessageW占据了100%的CPU使用率的最大部分。这是不是由于IntGetMessageW等待消息,但一些功能实际上是做什么。

Running the AQtime performance profiler, I see that IntGetMessageW occupies the largest part of that 100% CPU usage. This is not due to IntGetMessageW waiting for a message, but something the function is actually doing.

有一件事我还没有研究尚是,也许IntGetMessageW从来就不是一个快速的方法,也许WPF只是过度使用它。这可能是WPF中的数据绑定使用本地的Win32消息泵内WPF更新依赖属性。如果是这样的话,这可能是因为我的窗前,只是有太多的绑定。

The one thing I haven't looked into yet is that maybe IntGetMessageW has never been a fast method, and maybe WPF simply overuses it. It is possible that data bindings in WPF use the native Win32 message pump to update Dependency Properties within WPF. If that is the case, it could be that my window simply has too many bindings.

这篇关于为什么GetMessageW占用大量的CPU使用率在我的WPF应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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