Understanding the WPF Dispatcher.BeginInvoke

后端 未结 2 1029
小蘑菇
小蘑菇 2021-01-01 16:26

I was under the impression that the dispatcher will follow the priority of the operations queued it and execute the operations based on the priority or the orde

2条回答
  •  醉梦人生
    2021-01-01 16:54

    This is because the first MessageBox is blocking the UI thread.

    What Dispatcher.BeginInvoke() is doing under the hood is taking your delegate and scheduling it to be run on the main UI thread during it's next idle period. However, MessageBox will block whichever thread it is called from until it is closed. This means that the second MessageBox cannot be displayed until the first is cleared because the UI thread scheduler sees that the thread is already in use (waiting for the first MessageBox to be cleared) and can't execute the next delegate containing the second MessageBox.

提交回复
热议问题