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

后端 未结 1 550
自闭症患者
自闭症患者 2020-12-16 11:25

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)
{
         


        
相关标签:
1条回答
  • 2020-12-16 12:16

    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.

    0 讨论(0)
提交回复
热议问题