我对 WPF 比较陌生。我正在检查一些看起来像这样的代码:
private void button_Click(object sender, RoutedEventArgs e)
{
//Queue on dispatcher in the background so it doesn't make the UI slow
Dispatcher.BeginInvoke(new dMyDelegate(PerformOperation), DispatcherPriority.Background);
}
从评论中,我猜测原始代码认为这对于使 UI 更具响应性是必要的,但是,我的理解是 Dispatcher.BeginInvoke 只是在 UI 线程上运行一些东西。既然 buttn_Click 已经在 UI 线程上,那有什么意义呢?也许我误解了 Dispatcher 和 BeginInvoke。在这种情况下,我假设 Dispatcher 是此方法所在的类(即 MainWindow.xaml)所拥有的调度程序。有人可以启发我吗?
谢谢