WPF:调度程序处理已被暂停,但消息仍在处理中

编程入门 行业动态 更新时间:2024-10-23 01:30:36
本文介绍了WPF:调度程序处理已被暂停,但消息仍在处理中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个WPF项目,当我尝试在RowLoad事件上运行此代码时,我得到了下面的错误:

private void ParentGridView_OnRowLoaded(object sender,EventArgs e) {尝试 { if(((RadGridView)sender).Columns!= null) { MessageBox.Show(((RadGridView)发送方).Columns.Count.ToString(CultureInfo.InvariantCulture)); } } catch(Exception ex) { MessageBox.Show(ex.Message);

错误:调度程序处理已暂停,但消息仍然在处理中。

请注意,GridView控件是Telerik RadGridView

解决方案

这个答案描述了和你一样的情况。 (它引用了这个答案一个不同的网站)。

调度程序处理被暂停,以避免更新可视化树时的重入问题。

如果您确实需要显示一个消息框来响应您的Row Loaded事件,则需要使用Dispatcher.BeginInvoke()所以,替换:

MessageBox.Show(((RadGridView)sender ).Columns.Count.ToString(CultureInfo.InvariantCulture));

附带:

var msg =((RadGridView)sender).Columns.Count.ToString(CultureInfo.InvariantCulture); Dispatcher.BeginInvoke(new Action(()=> MessageBox.Show(msg)));

如果此代码位于WPF对象中,则 Dispatcher 属性可用。否则,您需要从其他地方获取它。

I Have a WPF Project, When i try to Run This Code On RowLoad Event I got below Error :

private void ParentGridView_OnRowLoaded(object sender, EventArgs e) { try { if(((RadGridView)sender).Columns != null) { MessageBox.Show(((RadGridView)sender).Columns.Count.ToString(CultureInfo.InvariantCulture)); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }

Error : Dispatcher processing has been suspended, but messages are still being processed.

Note That the GridView Control is Telerik RadGridView

解决方案

This answer describes the same situation as yours. (It references this answer on a different website).

The dispatcher processing is suspended to avoid reentrancy problems when updating the visual tree.

If you really need to display a message box in response to your "Row Loaded" event, you need to defer the call using `Dispatcher.BeginInvoke().

So, replace:

MessageBox.Show(((RadGridView)sender).Columns.Count.ToString(CultureInfo.InvariantCulture));

with:

var msg = ((RadGridView)sender).Columns.Count.ToString(CultureInfo.InvariantCulture); Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(msg)));

If this code is in a WPF object, then the Dispatcher property is available. Otherwise, you need to get it from somewhere else.

更多推荐

WPF:调度程序处理已被暂停,但消息仍在处理中

本文发布于:2023-10-13 00:06:09,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:已被   消息   程序   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!