中间哪一段能在非UI线程执行吗,如果可以的话,用异步的方式即可,代码示例如下:
private void Button_Click(object sender, RoutedEventArgs e) { var button = sender as Button; button.Visibility = Visibility.Hidden; Task.Run(() => { System.Threading.Thread.Sleep(2000); Dispatcher.BeginInvoke(new Action(() => { button.Visibility = System.Windows.Visibility.Visible; })); }); }
参考下面的博文,写了DoEvent方法后,在设置Visible后调用,即可更新界面
http://www.cnblogs.com/loveis715/archive/2012/01/11/2319976.html
一楼正解