WPF控件永远冻结,但所有事件均已接收并处理 [英] Wpf controls frozen forever, but all events are received and processed

查看:102
本文介绍了WPF控件永远冻结,但所有事件均已接收并处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的工作中,我们有这个应用程序,该应用程序将两个WinForms结合在一起和WPF控件.现在问题出在WPF控件上.当我们的WPF控件出现问题时, 例如,TreeView和ListView在后台从应用程序的另一部分接收数据.在这个时间点上,应用程序中的所有WPF控件偶尔会永远停止响应.它似乎已冻结.但是所有WinForms控件

冻结WPF控件后,我们尝试将VS Debugger附加到该控件上,如果我们单击任何TreeViewItem或任何其他WPF控件,则事件将被接收并执行 照常进行.甚至视图模型也将具有更新后的值,但仅仅是UI没有更新,这使其显示为冻结状态.


什么可能阻止UI更新,并阻止调度程序处理这些操作? /span>

请帮忙,自从过去15天以来,这个问题就让我无法入睡.

我尝试过的操作:

我已经尝试注释掉Dispatcher.BeginInvoke(...)代码应用程序,并怀疑此Dispatcher可能在这里弄乱了事情.但是那
我们还使用snoop和WPF跟踪检查了Binding错误,但未发现此类错误.

我尝试通过跟踪Dispatcher Hook的OperationPosted,OperationStarted,OperationCompleted和OperationAborted事件来进行跟踪,并发现问题何时可恢复 将会触发一系列的OperationPosted事件,然后是OperationAborted,这意味着发布到消息队列中的任何内容都不会得到处理(仅当问题可重现时,否则它才能正常运行 y).

At my work, we have this application which has the combination of both WinForms and WPF controls. Now the issue is with WPF controls. The issue happens when our WPF control, say, a TreeView and a ListView receives data from the other part of the application in the background. At this point of time, sporadically, the all WPF controls in the application stops responding forever. It appears to be frozen. But all the WinForms controls continues to work without any Hiccups.

When the WPF controls are frozen, we tried to attach VS Debugger to it, found that if we click on any TreeViewItem or any other WPF control the event is received and execution proceeds as usual. Even the view model will have the updated values, but it is just that the UI is not updated, which making it appear frozen.



What could possibly stop UI from getting updated, and stop dispatcher from processing the operations?

Please help, this issue is not letting me sleep since past 15 days.

What I have tried:

I have already tried commenting out the Dispatcher.BeginInvoke(...) codes in our application, with the suspicion that this Dispatcher could be messing up things here. But that wasn't the case, as the issue was reproducible even after commenting it out.

We also checked for the Binding errors, using snoop and WPF traces but no such errors found.

I tried tracing by subsribing to OperationPosted, OperationStarted, OperationCompleted and OperationAborted events of Dispatcher Hook, and found when the issue is reprocible there will be a series of OperationPosted events fired, which will be followed by OperationAborted, which means that any thing posted to message queue is not being processed (only when the issue is reproducible, otherwise it functions properly).

推荐答案

>>什么可能阻止UI更新,并阻止调度程序处理操作?

调度程序线程可能正在忙于处理调度程序队列中添加次数过多的委托,或者正在忙于处理某些复杂的布局或运行您的某些自定义代码.无法访问您的实际代码是不可能的.

The dispatcher thread may be busy processing too frequently added delegates from the dispatcher queue or it may be busy processing some complex layout or running some custom code of yours. It is impossible to tell without having access to your actual code.

确保ItemsControls使用UI虚拟化,并且没有将它们中的任何一个放入StackPanel或其他具有无限空间的面板中.请参考MSDN上的以下页面,以获取有关如何优化性能的更多信息. 控件集: https://msdn.microsoft.com/zh-CN/library/cc716879(v=vs.110).aspx

Make sure that your ItemsControls use UI virtualization and that you have not put any of them inside a StackPanel or some other panel that has infinite space. Please refer to the following page on MSDN for more information about how to optimize the performance of controls: https://msdn.microsoft.com/en-us/library/cc716879(v=vs.110).aspx

还要确保您没有在UI线程上执行任何长时间运行的代码,并且您也没有在同一时间执行过多的小代码块.

Also make sure that you are not executing any long-running code on the UI thread and you are not executing small chunks of code too frequently on the same.

如果需要其他帮助,请将问题的可复制性最少的示例上载到OneDrive,并在此处发布指向该链接的链接.

Please upload a minimal reproducible sample of your issue to OneDrive and post the link to it here if you need any further help.

希望有帮助.

请记住,通过将有用的帖子标记为答案来关闭话题,然后在遇到新问题时开始新话题.请不要在同一线程中问几个问题.

Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


这篇关于WPF控件永远冻结,但所有事件均已接收并处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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