private void Parallel(object sender, RoutedEventArgs e)
{
    Task.Run(() => ChangeColour(Brushes.Red));
}
 
private void Standard(object sender, RoutedEventArgs e)
{
    ChangeColour(Brushes.Green);
}
 
//如果是在控件的UI线程上执行 则直接调用就行,不在同一个ui线程上就使用线程调度的方式
private void ChangeColour(Brush brush) { if (MyGrid.CheckAccess()) MyGrid.Background = brush; else MyGrid.Dispatcher.Invoke(() => { MyGrid.Background = brush; }); }

 

相关文章:

  • 2021-09-18
  • 2021-11-02
  • 2022-12-23
  • 2021-10-21
  • 2021-08-25
  • 2021-06-08
  • 2022-02-28
  • 2021-09-22
猜你喜欢
  • 2022-12-23
  • 2021-10-21
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案