首先是我的錯誤錯誤日誌條目調度拋出InvalidOperationException異常的Messagebox.Show在TextChanged事件
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項目/形式
確實在UI線程上的消息框代碼運行? – thumbmunkeys
據我所知,不確定,因爲它是來自UI控制的事件,它應該是??對?? – Daanvl
是否可以在MessageBox.Show()中提供所有者窗口?它有一個接受窗口所有者的重載簽名。 –