Trước hết đây là sự xâm nhập errorlog về lỗi của tôiDispatcher ném InvalidOperationException trên Messagebox.Show trong sự kiện 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)
đang Dù sao:
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
{
//
}
}
}
}}
Vì vậy, theo phương pháp messagebox.show . điều này chỉ xảy ra khi người dùng chuyển chế độ đọc sang chế độ chỉnh sửa trên biểu mẫu của tôi. điều này liên quan đến việc thu gọn vi hiển thị một số nhãn và điều khiển ui.
nếu sự kiện kích hoạt từ userinput mọi thứ đều ổn. Tôi muốn biết điều gì: Tại sao sự kiện thay đổi văn bản được kích hoạt khi ẩn và hiển thị một vài điều khiển. Tôi có thể làm gì để ngăn chặn lỗi này?
EDIT: mã ở trên nằm trong điều khiển wpf tùy chỉnh. đặt trong một winforms dự án/form
không MessageBox mã chạy trên thread UI? – thumbmunkeys
Không chắc chắn, như xa như tôi có thể nói, bởi vì một sự kiện của nó từ một điều khiển ui nó nên được ?? đúng?? – Daanvl
Bạn có thể cung cấp cửa sổ chủ sở hữu trong MessageBox.Show() không? Nó có chữ ký quá tải chấp nhận chủ cửa sổ. –