Dispatcher throws InvalidOperationException on Messagebox.Show in Textchanged event

后端 未结 1 1409
清酒与你
清酒与你 2020-12-03 17:35

First of all this is the errorlog entry on my error

crash program @ 15-9-2011 15:01:30error:System.InvalidOperationException: Dispatcher processing has been su

相关标签:
1条回答
  • 2020-12-03 18:32

    See this thread it describes the same problem as yours:

    The exception is done on purpose to prevent reentrancy bugs caused by weirdness resulting from altering the visual tree, while such an event (which itself has been triggered by the visual tree altering) is firing. If you really must confirm something when the state of a UI element changes, delaying with Dispatcher.BeginInvoke is probably the right thing to do.

    To run code on the UI Thread do the following:

     Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
         {
    
            if (MessageBox.Show("Geen resultaat gevonden, " + errortext + ".\n Wilt u overschakelen naar handmatig? ", "Handmatig?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                RB_handmatig.IsChecked = true;
            }
            else
            {
                //
            }
        }));
    
    0 讨论(0)
提交回复
热议问题