【发布时间】:2011-11-18 13:36:57
【问题描述】:
首先这是关于我的错误的错误日志条目
crash program @ 15-9-2011 15:01:30error:System.InvalidOperationException: Dispatcher processing has been suspended, but messages are still being processed.
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
无论如何代码:
private void TB_postcode_cijfers_TextChanged(object sender, TextChangedEventArgs e){
if (TB_postcode_cijfers.Text != string.Empty || TB_postcode_cijfers.Text.Length > 0)
{
LBL_postcode.Content = Postcode_cijfers + Postcode_letters;
if (TB_postcode_cijfers.Text.Length == 4 && TB_postcode_letters.Text.Length == 2)
{
if (!ZoekOpPostcode(Injectioncheck(TB_postcode_cijfers.Text + TB_postcode_letters.Text)))
{
//MessageBox.Show("Geen resultaat gevonden, " + errortext);
if (MessageBox.Show("Geen resultaat gevonden, " + errortext + ".\n Wilt u overschakelen naar handmatig? ", "Handmatig?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
RB_handmatig.IsChecked = true;
}
else
{
//
}
}
}
}}
所以在 messagebox.show 方法上。 这只发生在用户在我的表单上将阅读模式切换到编辑模式时。 这涉及折叠并显示一些标签和 ui 控件。
如果事件从用户输入触发,一切都很好。 我想知道的: 为什么在隐藏和显示一些控件时会触发 textchanged 事件。 我能做些什么来防止这个错误?
编辑: 上面的代码在自定义 wpf 控件中。放在一个winforms项目/表单中
【问题讨论】:
-
您的 MessageBox 代码是否在 UI 线程上运行?
-
不确定,据我所知,因为它应该是来自 ui 控件的事件?对吗??
-
是否可以在 MessageBox.Show() 中提供所有者窗口?它有一个接受窗口所有者的重载签名。
-
它在一个自定义控件中,我在一些(旧)winforms 和其他(新)wpf 窗口中使用......但我会检查我是否可以让它工作
-
我可以提供表格但不能提供窗口......
标签: c# wpf custom-controls